json-schema-faker 0,1 editorconfig eslint travis-ci Bower npm

JSON-Schema + fake data generators

JSON Schema Faker logo

Build Status NPM version Bower version Coverage Status

Dependency Status devDependency Status

Inline docs Typedoc

Use JSON Schema along with fake generators to provide consistent and meaningful fake data for your system.

We are looking for contributors! If you wanna help us make jsf more awesome, simply write us so!

NEW in JSON Schema Faker: store schemas online!

save JSON Schema online

Table of contents

Online demo

See online demo. You can save your schemas online and share the link with your collaborators.


jsf is installable through 3 different channels:


Install json-schema-faker with npm:

npm install json-schema-faker --save


Install json-schema-faker with bower:

bower install json-schema-faker --save


JSON-Schema-faker is also available at cdnjs.com. This means you can just include the script file into your HTML:

# remember to update the version number!
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/json-schema-faker/0.3.4/json-schema-faker.min.js"></script>

It will be fetched from the Content Delivery Network without installing any node.js package.

You can see an example JS fiddle based on jsf loaded from cdnjs.


JSON-Schema-faker (or jsf for short) combines two things:

  • The JSON-schema specification, that defines what is the allowed content of a JSON document
  • Fake data generators, that are used to generate basic or complex data, conforming to the schema. Following libraries come bundled with jsf:

Example usage

var jsf = require('json-schema-faker');

var schema = {
  type: 'object',
  properties: {
    user: {
      type: 'object',
      properties: {
        id: {
          $ref: '#/definitions/positiveInt'
        name: {
          type: 'string',
          faker: 'name.findName'
        email: {
          type: 'string',
          format: 'email',
          faker: 'internet.email'
      required: ['id', 'name', 'email']
  required: ['user'],
  definitions: {
    positiveInt: {
      type: 'integer',
      minimum: 0,
      exclusiveMinimum: true

var sample = jsf(schema);

// "[object Object]"

// "John Doe"

(demo »)

jsf.version attribute is available to check which version you’re using:

var jsf = require('json-schema-faker');
// "0.3.6"

More examples

Gist demos

Clone these gists and execute them locally (each gist has its own readme with instructions):

  • jsf console - minimal example of jsf working directly under command line
  • jsf grunt - example of jsf working under grunt.js



Use angular-jsf module (installable via npm and bower) to get jsf working in your angular app out of the box! And check out angular-jsf demo.

Grunt plugin

Use grunt-jsonschema-faker to automate running json-schema-faker against your JSON schemas.

JSON Schema specification support

Currently jsf supports the JSON-Schema specification draft-04 only.

If you want to use draft-03, you may find useful information here.

Supported keywords

Below is the list of supported keywords:

  • $ref &mdash; Resolve internal references only, and/or external if provided.
  • required &mdash; All required properties are guaranteed, if not can be omitted.
  • pattern &mdash; Generate samples based on RegExp values.
  • format &mdash; Core formats only: date-time, email, hostname, ipv4, ipv6 and uridemo »
  • enum &mdash; Returns any of these enumerated values.
  • minLength, maxLength &mdash; Applies length constraints to string values.
  • minimum, maximum &mdash; Applies constraints to numeric values.
  • exclusiveMinimum, exclusiveMaximum &mdash; Adds exclusivity for numeric values.
  • multipleOf &mdash; Multiply constraints for numeric values.
  • items &mdash; Support for subschema and fixed item values.
  • minItems, maxItems &mdash; Adds length constraints for array items.
  • uniqueItems &mdash; Applies uniqueness constraints for array items.
  • additionalItems &mdash; Partially supported (?)
  • allOf, oneOf, anyOf &mdash; Subschema combinators.
  • properties &mdash; Object properties to be generated.
  • minProperties, maxProperties &mdash; Adds length constraints for object properties.
  • patternProperties &mdash; RegExp-based object properties.
  • additionalProperties &mdash; Partially supported (?)
  • dependencies &mdash; Not supported yet (?)
  • not &mdash; Not supported yet (?)

Using references

Inline references are fully supported (json-pointers) but external can’t be resolved by jsf.

In order to achieve that you can use refaker and then use the resolved schemas:

var schema = {
  type: 'object',
  properties: {
    someValue: {
      $ref: 'otherSchema'

var refs = [
    id: 'otherSchema',
    type: 'string'

var sample = jsf(schema, refs);

// "voluptatem"

Faking values

jsf has built-in generators for core-formats, Faker.js and Chance.js are also supported.

You can use faker or chance properties but they are optional:

  "type": "string",
  "faker": "internet.email"

(demo »)

The above schema will invoke faker.internet.email().

Note that both generators has higher precedence than format.

You can also use standard JSON Schema keywords, e.g. pattern:

  "type": "string",
  "pattern": "yes|no|maybe|i don't know"

(demo »)

Advanced usage of faker.js and Chance.js

In following inline code examples the faker and chance variables are assumed to be created with, respectively:

var faker = require('faker');

var Chance = require('chance'),
  chance = new Chance();

Another example of faking values is passing arguments to the generator:

  "type": "string",
  "chance": {
    "email": {
      "domain": "fake.com"

(demo »)

which will invoke chance.email({ "domain": "fake.com" }). This example works for single-parameter generator function.

However, if you pass multiple arguments to the generator function, just pass them wrapped in an array. In the example below we use the faker.finance.amount(min, max, dec, symbol) generator which has 4 parameters. We just wrap them with an array and it’s equivalent to faker.finance.amount(100, 10000, 2, "$"):

  "type": "object",
  "properties": {
    "cash": {
      "type": "string",
      "faker": {
        "finance.amount": [100, 10000, 2, "$"]
  "required": [

(demo »)

However, if you want to pass a single parameter that is an array itself, e.g. chance.pickone(["banana", "apple", "orange"]), just like described here, then you need to wrap it with an array once more (twice in total). The outer brackets determine that the content is gonna be a list of params injected into the generator. The inner brackets are just the value itself - the array we pass:

  "type": "object",
  "properties": {
    "food": {
      "type": "string",
      "chance": {
        "pickone": [
  "required": [

(demo »)


Since 0.3.0 the faker and chance dependencies aren’t shipped by default, in order to use both generators you MUST install them with npm install faker chance --save.

Custom formats

Additionally, you can add custom generators for those:

jsf.format('semver', function(gen, schema) {
  return gen.randexp('^\\d\\.\\d\\.\\d{1,2}$');

Now that format can be generated:

  "type": "string",
  "format": "semver"


  • format() &mdash; Return all registered formats (custom only)
  • format(obj) &mdash; Register formats by key/value &rarr; name/callback
  • format(name) &mdash; Returns that format generator (undefined if not exists)
  • format(name, callback) &mdash; Register a custom format by name/callback


  • gen (object) &mdash; Built in generators
    • faker (object) &mdash; Faker.js instance
    • chance (object) &mdash; Chance.js instance
    • randexp (function) &mdash; Randexp generator
  • schema (object) &mdash; The schema for input

Note that custom generators has lower precedence than core ones.

Custom Options

You may define following options for jsf that alter its behavior:

  • failOnInvalidTypes: boolean - don’t throw exception when invalid type passed
  • defaultInvalidTypeProduct: - default value generated for a schema with invalid type (works only if failOnInvalidTypes is set to false)

Set options just as below:

  failOnInvalidTypes: false

Extending dependencies

You may extend Faker.js:

var jsf = require('json-schema-faker');

jsf.extend('faker', function(faker){
  faker.locale = "de"; // or any other language
  faker.custom = {
    statement: function(length) {
      return faker.name.firstName() + " has " + faker.finance.amount() + " on " + faker.finance.account(length) + ".";
  return faker;

var schema = {
  "type": "string",
  "faker": {
    "custom.statement": [19]

var sample = jsf(schema);

or if you want to use faker’s individual localization packages, simply do the following:

jsf.extend('faker', function() {
  // just ignore the passed faker instance
  var faker = require('faker/locale/de');
  // do other stuff
  return faker;

You can also extend Chance.js, using built-in chance.mixin function:

var jsf = require('json-schema-faker');

jsf.extend('chance', function(chance){
    'user': function() {
      return {
        first: chance.first(),
        last: chance.last(),
        email: chance.email()

  return chance;

var schema = {
  "type": "string",
  "chance": "user"

var sample = jsf(schema);

The first parameter of extend function is the generator name (faker or chance). The second one is the function that accepts the dependency library; the function alters the library and returns it.

Inferred Types

JSON Schema does not require you to provide the type property for your JSON Schema documents and document fragments.

But since jsf uses the type property to create the proper fake data, we attempt to infer the type whenever it is not provided. We do this based on the JSON Schema validation properties you use.

Now this means that if you do not use any of the JSON Schema validation properties, jsf will not be able to infer the type for you and you will need to explicitly set your type manually.)

Below is the list of JSON Schema validation properties and the inferred type based on the property:


  • additionalItems
  • items
  • maxItems
  • minItems
  • uniqueItems

integer (Number uses the same properties so if you need number, set your type explicitly)

  • exclusiveMaximum
  • exclusiveMinimum
  • maximum
  • minimum
  • multipleOf


  • additionalProperties
  • dependencies
  • maxProperties
  • minProperties
  • patternProperties
  • properties
  • required


  • maxLength
  • minLength
  • pattern

Swagger extensions

jsf supports OpenAPI Specification vendor extensions, i.e.

  • x-faker property that stands for faker property (demo »)
  • x-chance property that stands for chance property (demo »)

Thanks to it, you can use valid swagger definitions for jsf data generation.


JSON-Schema-faker might be used in Node.js as well as in the browser. In order to execute jsf in a browser, you should include the distribution file from dist directory. Each new version of jsf is bundled using browserify and stored by the library maintainers. The bundle includes full versions of all dependencies.

However, you may want to bundle a smaller package of jsf, because: * you want to reduce the bundle file size * you don’t need all languages from faker.js * you wish to use chance.js only and get rid of other dependencies * or for any other reason… In that case you may bundle the distribution yourself manually. It’s easily achievable: just modify the lib/util/container.js file and either remove o rmodify the require calls (they’re directly used by browserify to include dependencies). Automation of this feature is expected in near future.


We are more than happy to welcome new contributors, our project is heavily developed, but we need more power :) Please see contribution guide, you can always contact us to ask how you can help.

Technical Documentation

If you want to contribute, take a look at the technical documentation page. You may find some important information there making it easier to start.

Moreover, if you find something unclear (e.g. how does something work) or would like to suggest improving the docs, please submit an issue, we’ll gladly provide more info for future contributors.



There were some existing projects or services trying to achieve similar goals as jsf:

but they were either incomplete, outdated, broken or non-standard. That’s why jsf was created.

Bitdeli Badge

Related Repositories



JSON-Schema + fake data generators ...



Grunt task generating fake data according to JSON schema ...



AngularJS mock factory! Generating semantic mocks on the fly, basing on JSON-Schema-faker ...



Create dummy data with JSON schema ...



JSON-Schema + Faker ...

Top Contributors

pateketrueke ducin greenkeeperio-bot whitlockjc PeterDaveHello AndreSteenveld alockwood05 arjanvanderleden bitdeli-chef presidento pksunkara Raynos omerts


package version
deref ^0.7.0
json-schema-ref-parser ^3.1.2
randexp ^0.4.5
tslib ^1.7.1
dev casual-cjs ^1.5.10
chance ^1.0.9
chokidar ^1.7.0
clone ^2.1.1
codecov ^2.2.0
faker ^4.1.0
fs-extra ^4.0.0
google-closure-compiler-js ^20170626.0.0
istanbul ^0.4.5
jasmine-node 2.0.0-beta4
jayschema ^0.3.1
lodash.template ^4.4.0
rollup ^0.42.0
rollup-plugin-commonjs ^8.0.2
rollup-plugin-node-resolve ^3.0.0
semver ^5.3.0
tarima ^3.2.1
ts-node ^3.0.4
tslint ^5.3.2
tv4 ^1.3.0
typedoc ^0.7.1
typescript ^2.3.4
z-schema ^3.18.2


-   v0.3.6 zip tar
-   v0.3.5 zip tar
-   v0.3.4 zip tar
-   v0.3.3 zip tar
-   v0.3.2 zip tar
-   v0.3.1 zip tar
-   v0.3.0 zip tar
-   v0.2.16 zip tar
-   v0.2.15 zip tar
-   v0.2.14 zip tar
-   v0.2.13 zip tar
-   v0.2.12 zip tar
-   v0.2.11 zip tar
-   v0.2.10 zip tar
-   v0.2.9 zip tar
-   v0.2.8 zip tar
-   v0.2.7 zip tar
-   v0.2.6 zip tar
-   v0.2.5 zip tar
-   v0.2.4 zip tar
-   v0.2.3 zip tar
-   v0.2.2 zip tar
-   v0.2.1 zip tar
-   v0.2.0 zip tar
-   v0.1.13 zip tar
-   v0.1.12 zip tar
-   v0.1.11 zip tar
-   v0.1.10 zip tar
-   v0.1.9 zip tar
-   v0.1.8 zip tar