# mock-json-schema
[](https://github.com/anttiviljami/mock-json-schema/actions?query=workflow%3ACI)
[](https://david-dm.org/anttiviljami/mock-json-schema)
[](https://www.npmjs.com/package/mock-json-schema)
[](https://www.npmjs.com/package/mock-json-schema)
[](https://lgtm.com/projects/g/anttiviljami/mock-json-schema/alerts/)
[](https://lgtm.com/projects/g/anttiviljami/mock-json-schema/context:javascript)
[](https://github.com/anttiviljami/mock-json-schema/blob/master/LICENSE)
[](http://spiceprogram.org/oss-sponsorship)
[](https://buymeacoff.ee/anttiviljami)
Simple utility to mock example objects based on JSON schema definitions
## Features
- [x] Minimal & deterministic. Predictable single example with no randomisation involved
- [x] Thoroughly [tested](https://github.com/anttiviljami/mock-json-schema/blob/master/src/mock.test.ts) feature set
- [x] Supports `example`, `default`
- [x] Supports `anyOf`, `allOf`, `oneOf`
- [x] Built-in examples for following string formats:
- `email`
- `hostname`
- `ipv4`
- `ipv6`
- `uri`
- `uri-reference`
- `uri-template`
- `json-pointer`
- `date-time`
- `uuid`
- [x] TypeScript types included
- [ ] Supports $ref pointers
## Usage
```javascript
const { mock } = require('mock-json-schema');
const assert = require('assert');
const schema = {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'integer',
minimum: 1,
},
name: {
type: 'string',
example: 'John Doe',
},
email: {
type: 'string',
format: 'email',
},
},
},
};
assert.deepEqual(mock(schema), [{ id: 1, name: 'John Doe', email: 'user@example.com' }]);
```
View more [examples](https://github.com/anttiviljami/mock-json-schema/blob/master/src/mock.test.ts)
## Contributing
mock-json-schema is Free and Open Source Software. Issues and pull requests are more than welcome!
[<img alt="The Chilicorn" src="http://spiceprogram.org/assets/img/chilicorn_sticker.svg" width="250" height="250">](https://spiceprogram.org/oss-sponsorship)