Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
/ jaymock Public archive

Minimal fake JSON test data generator.

Notifications You must be signed in to change notification settings


Repository files navigation


Minimal fake JSON test data generator.

CircleCI XO Codecov


~ ❯❯❯ npm install @meeshkanml/jaymock


const jaymock = require('@meeshkanml/jaymock')

const data = {
  firstName: 'name.firstName',
  lastName: 'name.lastName',
  ssn: 'ssn',
  address: {
    streetAddress: 'address.streetAddress',
    city: '',
    zipCode: 'address.zipCode'
  emails: '',
  ipAddress: 'internet.ip',
  _repeat: 2

const jm = jaymock()

const randExp = require('randexp').randexp
// Add custom functions using `.extend()`
  ssn: () => randExp(/^\d{3}-\d{2}-\d{4}$/)

const fakeData = jm.populate(data)
      firstName: 'Marguerite',
      lastName: 'Will',
      ssn: '076-86-6001',
      address: {
        streetAddress: '4509 Abernathy Port',
        city: 'Port Charles',
        zipCode: '26322'
      emails: '',
      ipAddress: ''
      firstName: 'Fredrick',
      lastName: 'McClure',
      ssn: '610-42-4980',
      address: {
        streetAddress: '56363 Goyette Station',
        city: 'West Floydmouth',
        zipCode: '73634-6751'
      emails: '',
      ipAddress: ''

Mock API using express

const jaymock = require('@meeshkanml/jaymock')
const express = require('express')

app = express()

const jm = jaymock()
jm.extend('chance', new require('chance')())'/', (req, res) => res.json(jm.populate(req.body)))




Returns an object, populated with fake data.


Type: object

Each object's value can be one of Faker.js's API methods, in the format '{topic}.{subtopic}' (e.g. 'name.firstName') or a custom method, defined using the .extend function, in the format '{function_name}' or {function_name}.{nested_function_name} (e.g. 'foo' will call foo() and '' will call

A fake value can be generated n times, into an array of n values, by including |n at the end of the individual object's method name (e.g. 'name.firstName|5' will generate an array, populated with 5 fake first names). This also works with custom functions, accordingly.

To use the faker.fake() method (which permits the combination of faker API methods), use the format 'fake({mustache_strings})' (e.g. 'fake({{name.lastName}}, {{name.firstName}} {{name.suffix}})').

.extend(name, body)

Adds a custom data generation function that can be called in the .populate template using the value of name.


Type: string


Type: function


Adds custom data generation functions that can be called in the .populate template using the value of each object key.


Type: object

Each object key should be the relevant function's name and value the function's body (e.g. { 'chance': new require('chance')() }).


Sets Faker.js's language locale.


Type: string

Any of Faker.js's locale options.


Sets Faker.js's randomness seed.


Type: number



Thanks for wanting to contribute! We will soon have a contributing page detailing how to contribute. Meanwhile, feel free to star this repository, open issues, and ask for more features and support.

Please note that this project is governed by the Meeshkan Community Code of Conduct. By participating in this project, you agree to abide by its terms.


  • Faker.js is used as jaymock's core fake data generator.


MIT © Meeshkan