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

mock-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-json-schema

Simple utility to mock example objects based on JSON schema definitions

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

mock-json-schema

CI Dependencies npm version npm downloads Total alerts Language grade: JavaScript License Sponsored Buy me a coffee

Simple utility to mock example objects based on JSON schema definitions

Features

  • Minimal & deterministic. Predictable single example with no randomisation involved
  • Thoroughly tested feature set
  • Supports example, default
  • Supports anyOf, allOf, oneOf
  • Built-in examples for following string formats:
    • email
    • hostname
    • ipv4
    • ipv6
    • uri
    • uri-reference
    • uri-template
    • json-pointer
    • date-time
    • uuid
  • TypeScript types included
  • Supports $ref pointers

Usage

const { mock } = require('mock-json-schema');
const assert = require('assert');

const schema = {
  type: 'array',
  items: {
    type: 'object',
    properties: {
      id: {
        type: 'integer',
        minimum: 1,
      },
      name: {
        type: 'string',
        example: 'John Doe',
      },
      email: {
        type: 'string',
        format: 'email',
      },
    },
  },
};

assert.deepEqual(mock(schema), [{ id: 1, name: 'John Doe', email: 'user@example.com' }]);

View more examples

Contributing

mock-json-schema is Free and Open Source Software. Issues and pull requests are more than welcome!

The Chilicorn

Keywords

FAQs

Package last updated on 10 Jun 2021

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