{"id":48264,"library":"json-schema-default","title":"json-schema-default","description":"Generate an object based on default values defined in a JSON Schema. This package extracts only the default values from a schema, ignoring 'required' constraints, making it suitable for pre-filling forms or merging with existing data to ensure defaults are present. v1.0.2 targets Node 18+ and ships TypeScript types. It differs from json-schema-empty (which respects 'required' and creates placeholder values) by focusing strictly on explicit defaults. Release cadence: low (single stable release as of 2024). Key alternatives: AJV's assignDefaults, json-schema-empty, json-schema-fill-defaults.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/mdornseif/json-schema-default","tags":["javascript","JSON","schema","JSON-Schema","Data Generation","typescript"],"install":[{"cmd":"npm install json-schema-default","lang":"bash","label":"npm"},{"cmd":"yarn add json-schema-default","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-schema-default","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; no CommonJS wrapper provided.","wrong":"const jsonDefault = require('json-schema-default')","symbol":"jsonDefault","correct":"import { jsonDefault } from 'json-schema-default'"},{"note":"The package also exports a default export identical to named export jsonDefault.","wrong":"import { default } from 'json-schema-default'","symbol":"default export","correct":"import jsonDefault from 'json-schema-default'"},{"note":"TypeScript types are bundled; use type import for type-only usage.","wrong":null,"symbol":"types","correct":"import type { JsonSchemaDefault } from 'json-schema-default'"}],"quickstart":{"code":"import { jsonDefault } from 'json-schema-default'\n\nconst schema = {\n  type: 'object',\n  properties: {\n    name: { type: 'string', default: 'John' },\n    age: { type: 'number', default: 30 },\n    email: { type: 'string' }\n  }\n}\n\nconst result = jsonDefault(schema)\nconsole.log(result) // { name: 'John', age: 30 }","lang":"typescript","description":"Generates a plain object from JSON Schema defaults; properties without default are omitted."},"warnings":[{"fix":"Use json-schema-empty or json-schema-empty-strings if you need placeholders.","message":"Properties without a 'default' value are omitted from result. Do not assume all properties appear.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Simplify schema or pre-resolve with a tool like AJV before calling jsonDefault.","message":"Only top-level 'default' values are used. Nested schemas with defaults in allOf/anyOf/oneOf may not be resolved.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use dynamic import() or upgrade Node to 18+.","message":"ESM-only; Node <18 will throw ERR_REQUIRE_ESM if using require().","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Validate schema with AJV before passing to jsonDefault.","message":"The function does not validate input; passing an invalid schema may throw unexpected errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'18':51 '2024':84 'ajv':87 'altern':86 'assigndefault':89 'base':8 'cadenc':77 'constraint':29 'creat':67 'data':42,105 'default':4,10,22,45,75,98 'defin':12 'differ':57 'empti':62,93 'ensur':44 'exist':41 'explicit':74 'extract':19 'fill':36,97 'focus':71 'form':37 'generat':5,106 'ignor':27 'javascript':99 'json':2,15,60,91,95,100,103 'json-schema':102 'json-schema-default':1 'json-schema-empti':59,90 'json-schema-fill-default':94 'key':85 'low':78 'make':30 'merg':39 'node':50 'object':7 'packag':18 'placehold':68 'pre':35 'pre-fil':34 'present':47 'releas':76,81 'requir':28,65 'respect':64 'schema':3,16,26,61,92,96,101,104 'ship':53 'singl':79 'stabl':80 'strict':72 'suitabl':32 'target':49 'type':55 'typescript':54,107 'v1.0.2':48 'valu':11,23,69","created_at":"2026-06-07T16:55:43.952307+00:00","updated_at":"2026-06-07T16:55:43.952307+00:00","problems":[{"fix":"Add \"type\": \"module\" in package.json or use dynamic import().","cause":"Package is ESM-only but project uses CommonJS.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Use import { jsonDefault } from 'json-schema-default'.","cause":"Incorrect import: using default import as named import.","error":"TypeError: jsonDefault is not a function"},{"fix":"Use import statement instead of require().","cause":"Using require() in an ESM context.","error":"ReferenceError: require is not defined in ES module scope"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/mdornseif/json-schema-default","github":"https://github.com/mdornseif/json-schema-default","docs":null,"changelog":null,"pypi":null,"npm":"json-schema-default","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}