Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
json-schema-faker
Advanced tools
The json-schema-faker npm package is a tool that generates fake data based on JSON Schema definitions. It is useful for testing, prototyping, and mocking APIs.
Basic JSON Schema Support
Generates fake data based on a simple JSON Schema. The schema defines an object with 'name' and 'age' properties, and json-schema-faker generates a corresponding fake object.
const jsf = require('json-schema-faker');
const schema = {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'integer' }
},
required: ['name', 'age']
};
const fakeData = jsf.generate(schema);
console.log(fakeData);
Custom Formats
Allows the creation of custom formats for generating specific types of fake data. In this example, a custom format 'customFormat' is defined to always return 'customValue'.
const jsf = require('json-schema-faker');
jsf.format('customFormat', () => 'customValue');
const schema = {
type: 'object',
properties: {
customField: { type: 'string', format: 'customFormat' }
}
};
const fakeData = jsf.generate(schema);
console.log(fakeData);
Extending with Faker.js
Integrates with Faker.js to use its extensive library of fake data generators. In this example, the schema uses Faker.js to generate a fake email address.
const jsf = require('json-schema-faker');
const faker = require('faker');
jsf.extend('faker', () => faker);
const schema = {
type: 'object',
properties: {
email: { type: 'string', faker: 'internet.email' }
}
};
const fakeData = jsf.generate(schema);
console.log(fakeData);
Faker.js is a popular library for generating fake data. It provides a wide range of data types and is highly customizable. Unlike json-schema-faker, it does not use JSON Schema definitions but offers a rich API for generating fake data directly.
Chance.js is another library for generating random data. It is lightweight and provides a simple API for generating various types of random data. Like Faker.js, it does not use JSON Schema definitions but offers a straightforward way to generate random data.
Mockaroo is an online tool and API for generating fake data. It supports a wide range of data types and allows users to define schemas using a web interface. It is more user-friendly for non-developers compared to json-schema-faker.
Use JSON Schema along with fake generators to provide consistent and meaningful fake data for your system.
Breaking-changes towards v0.5.x
API:
jsf()
and get a fully-dereferenced result. It will just generate given refs and inline ones, nothing else.
jsf.generate()
is the sync-version, with partial dereferencing through given refs, etc.jsf.resolve()
is the async-version, with full dereferencing, given refs are also supported.d.ts
definitions will be updated on time.Usage info from README.md was moved to
docs/
, read more.
We are more than happy to welcome new contributors, our project is still being developed, but we need more feedback!
Please see our contribution guide to learn how.
We have a gitter room for this project, if you want to contribute, talk about specific issues from the library, or you need help on json-schema topics just reach out to us!
Please take a look at the technical documentation page.
If you think
json-schema-faker
is adding value on what you're doing please consider buying me a coffee.Also, you can support the project via Open Collective.
FAQs
JSON-Schema + fake data generators
The npm package json-schema-faker receives a total of 195,616 weekly downloads. As such, json-schema-faker popularity was classified as popular.
We found that json-schema-faker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.