🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

json-schema-faker

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
j

json-schema-faker

JSON-Schema + fake data generators

0.5.9
latest
99

Supply Chain Security

100

Vulnerability

87

Quality

83

Maintenance

100

License

Version published
Weekly downloads
314K
-7.1%
Maintainers
2
Weekly downloads
 
Created
Issues
81

What is json-schema-faker?

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.

What are json-schema-faker's main functionalities?

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);

Other packages similar to json-schema-faker

FAQs

Package last updated on 07 Apr 2025

Did you know?

Socket

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.

Install

Related posts