Gathering detailed insights and metrics for json-schema-faker-bb
Gathering detailed insights and metrics for json-schema-faker-bb
Gathering detailed insights and metrics for json-schema-faker-bb
Gathering detailed insights and metrics for json-schema-faker-bb
npm install json-schema-faker-bb
Typescript
Module System
Node Version
NPM Version
JavaScript (70.24%)
HTML (9.45%)
Svelte (6.75%)
Less (5.38%)
CSS (4.85%)
TypeScript (1.33%)
Pug (1.11%)
Makefile (0.88%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3,376 Stars
1,347 Commits
340 Forks
44 Watchers
6 Branches
71 Contributors
Updated on Jul 11, 2025
Latest Version
0.5.0-rc12
Package Id
json-schema-faker-bb@0.5.0-rc12
Unpacked Size
880.08 kB
Size
223.50 kB
File Count
7
NPM Version
4.6.1
Node Version
7.10.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
5
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!
We've recently setup a gitter room for this project, if you want contribute, talk about specific issues from the library, or you need help on json-schema topics just reach us!
A release candidate for v0.5.x
series was released in order to support local/remote reference downloading thanks to json-schema-ref-parser
, this change forced jsf
to be completely async.
1var jsf = require('json-schema-faker'); 2 3var REMOTE_REF = 'https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json'; 4 5var schema = { 6 $ref: REMOTE_REF 7}; 8 9jsf.resolve(schema).then(function(result) { 10 console.log(JSON.stringify(result, null, 2)); 11});
WIP: BREAKING CHANGES
v0.4.x
and below) will not work, however the fix is easyUntil a polished v0.5.0
version is released we encourage you to use and test around this RC, the main API will remain intact but probably option names, or subtle behaviors can be introduced.
Examples, new ideas, tips and any kind of kindly feedback is greatly appreciated.
NEW: BACKWARD COMPATIBILITY
0.5.0-rc3
we introduced a jsf.resolve()
method for full-async results.0.5.0-rc3
the methods jsf.sync()
is REMOVED and the API for jsf()
will remain sync.Thanks for all your feedback in advance to everyone!
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.5.0-rc1/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:
Since v0.5.x
external generators are not longer bundled with jsf, however built-in defaults are shipped for all basic types and formats.
1var jsf = require('json-schema-faker'); 2 3var schema = { 4 type: 'object', 5 properties: { 6 user: { 7 type: 'object', 8 properties: { 9 id: { 10 $ref: '#/definitions/positiveInt' 11 }, 12 name: { 13 type: 'string', 14 faker: 'name.findName' 15 }, 16 email: { 17 type: 'string', 18 format: 'email', 19 faker: 'internet.email' 20 } 21 }, 22 required: ['id', 'name', 'email'] 23 } 24 }, 25 required: ['user'], 26 definitions: { 27 positiveInt: { 28 type: 'integer', 29 minimum: 0, 30 exclusiveMinimum: true 31 } 32 } 33}; 34 35jsf.resolve(schema).then(function(sample) { 36 console.log(sample); 37 // "[object Object]" 38 39 console.log(sample.user.name); 40 // "John Doe" 41});
(demo »)
jsf.version
attribute is available to check which version you're using:
1var jsf = require('json-schema-faker'); 2console.log(jsf.version); 3// "0.5.0-rc1"
Clone these gists and execute them locally (each gist has its own readme with instructions):
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.
Use grunt-jsonschema-faker
to automate running json-schema-faker
against your JSON schemas.
Use json-schema-faker-cli
to run jsf
from your command line.
Use json-schema-faker-loader
to execute jsf
as a webpack loader.
Currently jsf
supports the JSON-Schema specification draft-04 only.
If you want to use draft-03, you may find useful information here.
Below is the list of supported keywords:
$ref
— Resolve internal references only, and/or external if provided.required
— All required properties are guaranteed, if not can be omitted.pattern
— Generate samples based on RegExp values.format
— Core formats v4-draft only:
date-time
,
email
,
hostname
,
ipv4
,
ipv6
and uri
-- demo »enum
— Returns any of these enumerated values.minLength
, maxLength
— Applies length constraints to string values.minimum
, maximum
— Applies constraints to numeric values.exclusiveMinimum
, exclusiveMaximum
— Adds exclusivity for numeric values.multipleOf
— Multiply constraints for numeric values.items
— Support for subschema and fixed item values.minItems
, maxItems
— Adds length constraints for array items.uniqueItems
— Applies uniqueness constraints for array items.additionalItems
— Partially supported (?)allOf
, oneOf
, anyOf
— Subschema combinators.properties
— Object properties to be generated.minProperties
, maxProperties
— Adds length constraints for object properties.patternProperties
— RegExp-based object properties.additionalProperties
— Partially supported (?)dependencies
— Not supported yet (?)not
— Not supported yet (?)Inline references are fully supported (json-pointers) but external can't be resolved by jsf
.
Remote en local references are automatically resolved thanks to json-schema-ref-parser
.
1var schema = { 2 type: 'object', 3 properties: { 4 someValue: { 5 $ref: 'otherSchema' 6 } 7 } 8}; 9 10var refs = [ 11 { 12 id: 'otherSchema', 13 type: 'string' 14 } 15]; 16 17jsf.resolve(schema, refs).then(function(sample) { 18 console.log(sample.someValue); 19 // "voluptatem" 20});
Local references are always resolved from the process.cwd()
, of course you can specify a custom folder to look-up: jsf(schema, refs, cwd)
jsf
has built-in generators for core-formats, Faker.js and Chance.js (and others) are also supported but they require setup:
1jsf.extend('faker', function() { 2 return require('faker'); 3});
1{ 2 "type": "string", 3 "faker": "internet.email" 4}
(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
:
1{ 2 "type": "string", 3 "pattern": "yes|no|maybe|i don't know" 4}
(demo »)
In following inline code examples the faker
and chance
variables are assumed to be created with, respectively:
1var faker = require('faker'); 2 3var Chance = require('chance'), 4 chance = new Chance();
Another example of faking values is passing arguments to the generator:
1{ 2 "type": "string", 3 "chance": { 4 "email": { 5 "domain": "fake.com" 6 } 7 } 8}
(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, "$")
:
1{ 2 "type": "object", 3 "properties": { 4 "cash": { 5 "type": "string", 6 "faker": { 7 "finance.amount": [100, 10000, 2, "$"] 8 } 9 } 10 }, 11 "required": [ 12 "cash" 13 ] 14}
(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:
1{ 2 "type": "object", 3 "properties": { 4 "food": { 5 "type": "string", 6 "chance": { 7 "pickone": [ 8 [ 9 "banana", 10 "apple", 11 "orange" 12 ] 13 ] 14 } 15 } 16 }, 17 "required": [ 18 "food" 19 ] 20}
(demo »)
Additionally, you can add custom generators for those:
1jsf.format('semver', function() { 2 return jsf.random.randexp('\\d\\.\\d\\.[1-9]\\d?'); 3});
Now that format can be generated:
1{ 2 "type": "string", 3 "format": "semver" 4}
Usage:
Callback:
Note that custom generators has lower precedence than core ones.
You may define following options for jsf
that alter its behavior:
failOnInvalidTypes
: boolean - don't throw exception when invalid type passeddefaultInvalidTypeProduct
: - default value generated for a schema with invalid type (works only if failOnInvalidTypes
is set to false
)failOnInvalidFormat
: boolean - don't throw exception when invalid format passedmaxItems
: number - Configure a maximum amount of items to generate in an array. This will override the maximum items found inside a JSON Schema.maxLength
: number - Configure a maximum length to allow generating strings for. This will override the maximum length found inside a JSON Schema.random
: Function - a replacement for Math.random
to support pseudorandom number generation.alwaysFakeOptionals
: boolean - When true, all object-properties will be generated regardless they're required
or not.Set options just as below:
1jsf.option({ 2 failOnInvalidTypes: false 3});
You may extend Faker.js:
1var jsf = require('json-schema-faker'); 2 3jsf.extend('faker', function(){ 4 var faker = require('faker'); 5 6 faker.locale = "de"; // or any other language 7 faker.custom = { 8 statement: function(length) { 9 return faker.name.firstName() + " has " + faker.finance.amount() + " on " + faker.finance.account(length) + "."; 10 } 11 }; 12 return faker; 13}); 14 15var schema = { 16 "type": "string", 17 "faker": { 18 "custom.statement": [19] 19 } 20} 21 22jsf.resolve(schema).then(...);
or if you want to use faker's individual localization packages, simply do the following:
1jsf.extend('faker', function() { 2 // just ignore the passed faker instance 3 var faker = require('faker/locale/de'); 4 // do other stuff 5 return faker; 6});
You can also extend Chance.js, using built-in chance.mixin function:
1var jsf = require('json-schema-faker'); 2 3jsf.extend('chance', function(){ 4 var Chance = require('chance'); 5 var chance = new Chance(); 6 7 chance.mixin({ 8 'user': function() { 9 return { 10 first: chance.first(), 11 last: chance.last(), 12 email: chance.email() 13 }; 14 } 15 }); 16 17 return chance; 18}); 19 20var schema = { 21 "type": "string", 22 "chance": "user" 23} 24 25jsf.resolve(schema).then(...);
The first parameter of extend
function is the generator name (faker
, chance
, etc.). The second one is the function that must return the dependency library.
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:
array
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
object
additionalProperties
dependencies
maxProperties
minProperties
patternProperties
properties
required
string
maxLength
minLength
pattern
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 Rollup.js and stored by the library maintainers. The bundle includes full versions of all dependencies.
From v0.5.x
and beyond we'll not longer bundle external generators, locales and such due the unnecessary waste of time and space.
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.
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.
jsf
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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 12/14 approved changesets -- score normalized to 8
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More