📜  dummy json - Javascript (1)

📅  最后修改于: 2023-12-03 15:00:33.274000             🧑  作者: Mango

Dummy JSON - JavaScript

Dummy JSON is a tool for generating random data in JSON format. It can be used for testing, prototyping, or anything else that requires realistic sample data.

Features
  • Support for generating JSON data based on given data model schemas.
  • Rich set of data types and generators, including strings, numbers, dates, and more.
  • Customizable options for generating data, such as length, format, and randomness.
  • Ability to export generated JSON data to file or console output.
Usage

To use Dummy JSON in your JavaScript project, you can install it via npm:

npm install --save dummy-json

Then, import it into your project and use it to generate JSON data:

const dummyjson = require('dummy-json');

const dataModel = `
{
  "users": [
    {{#repeat 5}}
    {
      "id": {{@index}},
      "name": "{{firstName}} {{lastName}}",
      "email": "{{email}}",
      "age": {{int 18 60}},
      "gender": "{{gender}}",
      "createdAt": "{{moment 'YYYY-MM-DD HH:mm:ss'}}"
    }{{/repeat}}
  ]
}
`;

const jsonData = dummyjson.parse(dataModel);
console.log(jsonData);

This example generates an array of 5 user objects with random data such as names, emails, ages, genders, and creation dates.

Documentation

For more information on how to use Dummy JSON and its features, please refer to the official documentation.