Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-schema-faker

Package Overview
Dependencies
Maintainers
0
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-faker

JSON-Schema + fake data generators

  • 0.5.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

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

Keywords

FAQs

Package last updated on 02 Nov 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc