{"id":15663829,"url":"https://github.com/romeovs/json-schema-empty","last_synced_at":"2025-05-05T23:20:24.180Z","repository":{"id":31435274,"uuid":"34998879","full_name":"romeovs/json-schema-empty","owner":"romeovs","description":"deterministically generate simple data from json schema's","archived":false,"fork":false,"pushed_at":"2016-06-23T15:27:52.000Z","size":22,"stargazers_count":18,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T12:53:07.587Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/romeovs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-03T20:02:03.000Z","updated_at":"2025-01-08T23:01:54.000Z","dependencies_parsed_at":"2022-08-07T16:16:04.298Z","dependency_job_id":null,"html_url":"https://github.com/romeovs/json-schema-empty","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romeovs%2Fjson-schema-empty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romeovs%2Fjson-schema-empty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romeovs%2Fjson-schema-empty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romeovs%2Fjson-schema-empty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romeovs","download_url":"https://codeload.github.com/romeovs/json-schema-empty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252590927,"owners_count":21772989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T13:40:04.516Z","updated_at":"2025-05-05T23:20:24.129Z","avatar_url":"https://github.com/romeovs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-schema-empty\n\n[![Build Status](https://img.shields.io/travis/romeovs/json-schema-empty.svg?style=flat-square)][travis]\n[![Coverage Status](https://img.shields.io/coveralls/romeovs/json-schema-empty.svg?style=flat-square)][coveralls]\n[![Dependencies](https://img.shields.io/david/romeovs/json-schema-empty.svg?style=flat-square)][david]\n[![devDependencies](https://img.shields.io/david/dev/romeovs/json-schema-empty.svg?style=flat-square)][david-dev]\n[![license](https://img.shields.io/badge/license-ISC-373737.svg?style=flat-square)][license]\n[![gitter](https://img.shields.io/badge/GITTER-join%20chat%20→-00d86e.svg?style=flat-square)][gitter]\n\n\nGenerate simple data that matches a json schema.\n\nAll libraries that generate data from a json-schema I could find\ngenerate random data that conforms to a json schema.  This is nice\nfor testing but is not well-suited for generating default data for\nforms for example.\n\n`json-schema-empty` fills another niche.  The data it generates\nconforms to the following qualities:\n  - data is generated deterministically, if the schema is the same,\n   the date will be the same.\n  - the data is as simple as possible\n  - the data conforms to the *form* specified in the schema.  It will\n    sometimes fail to be valid according to the schema however.  The reason\n    for this is simple: you cannot generate all values automatically (see the\n    [rules](#rules) section for more info on this).\n\n## Usage\nTo install `json-schema-empty`, run:\n```sh\nnpm install json-schema-empty --save\n```\n\nThe api is simple:\n```js\nimport empty from 'json-schema-empty';\n// var empty = require('json-schema-empty').default; // when not using es6\n\nvar schema = {\n  type: 'object'\n, properties: {\n    foo: {\n      type: 'integer'\n    , minimum: 12\n    , multipleOf: 5\n    }\n  , bar: {\n      type: 'array'\n    , items: { type: 'integer' }\n    , minItems: 3\n    }\n  , baz: {\n      type: 'string',\n      minLength: 5\n    }\n  }\n, required: [ 'foo', 'bar', 'baz' ]\n};\n\nconsole.log(empty(schema));\n\n// logs:\n// {\n//   foo: 15,\n//   bar: [ 0, 0, 0 ],\n//   baz: ''\n// }\n```\n\n## Rules\n\n  - **string**: because it impossible to guess what the string\n    content should be, even when patterns and length limits are given,\n    a string schema always results in the empty string: `''`.\n\n  - **integer**: `json-schema-empty` tries to satisfy the `minimum`, `maximum`\n    and `multipleOf` constraints whenever possible wth the additional property\n    that, when it is possible, `0` is returned.\n\n  - **number**: just follows the `integer` schema.\n  - **object**: tries to create a minimal object with as few keys as possible.\n    Only keys that are in the `required` array are generated.\n\n    Object size is ignored completely, for the same reason that the\n    strings are empty: we cannot guess the keys.\n\n  - **array**: when the `item` type is given, and `minItems` is given,\n    the shortest array that matches this is generated.  It also works\n    when `items` is a tuple.  `maxItems` is ignored.  Whenever possible,\n    the empty array is returned.\n\n  - **boolean**: always results in `false`.\n  - **null**: always results in `null`.\n\n  - **oneOf**, **anyOf**: selects one of the accepted types and goes from there.\n  - **allOf**: `json-schema-empty` merges all schemas and works from that schema\n    to generate a value.\n  - **enum**: selects the first possible value.\n  - `$ref`: just works!\n\nWhenever specified, `json-schema-empty` uses the `default` value (even if it\ndoes not match the schema).\n\n### License\nThis code is licensed under the [ISC license][license]\n\n[travis]:    https://travis-ci.org/romeovs/json-schema-empty\n[coveralls]: https://coveralls.io/r/romeovs/json-schema-empty?branch=master\n[david]:     https://david-dm.org/romeovs/json-schema-empty\n[david-dev]: https://david-dm.org/romeovs/json-schema-empty#info=devDependencies\n[license]:   ./LICENSE\n[gitter]:    https://gitter.im/romeovs/json-schema-empty?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromeovs%2Fjson-schema-empty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromeovs%2Fjson-schema-empty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromeovs%2Fjson-schema-empty/lists"}