📅  最后修改于: 2023-12-03 15:00:33.274000             🧑  作者: Mango
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.
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.
For more information on how to use Dummy JSON and its features, please refer to the official documentation.