Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.
— Artwork by Ajay Karat
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 310,712 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 2 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.