Hey Dev Community! π
Iβm excited to share my latest project with you all: dynamic-json-generator! π This npm package is designed to help front-end developers quickly generate dynamic, fake JSON data for all your testing needs.
Why dynamic-json-generator?
When it comes to front-end development, having realistic test data is crucial. However, manually crafting this data can be tedious and time-consuming. Thatβs where dynamic-json-generator comes in! π
π What Is dynamic-json-generator?
dynamic-json-generator is an npm package that utilizes the power of @faker-js/faker to generate realistic JSON data for various testing scenarios. Whether you need single objects or a list of complex JSON structures, this tool has you covered.
π¦ Features
Single JSON Object Generation: Create a single JSON object based on a flexible template.
Multiple JSON Objects: Generate an array of JSON objects for bulk data testing.
Flexible Templates: Use a wide range of Faker data types including uuid, name, email, address, and more.
Supports Both CommonJS and ES Modules: Import with require or import based on your projectβs needs.
π οΈ Installation
To get started, simply run:
npm install dynamic-json-generator
𧩠Usage
Hereβs a quick example of how to use dynamic-json-generator:
const { generateJson, generateMultipleJson } = require('dynamic-json-generator');
// Define a template
const userTemplate = {
id: 'uuid',
name: 'fullName',
address: {
street: 'street',
city: 'city',
},
};
const postTemplate = {
id: 'uuid',
title: 'title',
body: 'body',
userId: 'uuid',
image: 'imageUrl', // or 'image.url' like @faker-js/faker
};
// Generate a single JSON object (English locale)
const singleJsonEn = generateJson(userTemplate);
console.log(singleJsonEn);
// Generate multiple JSON objects (English locale)
const multipleJsonEn = generateMultipleJson(userTemplate, 20);
console.log(multipleJsonEn);
// Generate a single JSON object (Burmese locale)
const singleJsonMm = generateJson(userTemplate, 'mm');
console.log(singleJsonMm);
// Generate multiple JSON objects (Burmese locale)
const multipleJsonMm = generateMultipleJson(userTemplate, 20, 'mm');
console.log(multipleJsonMm);
π Get Started Today!
Check out the GitHub repository for more details and contribute to the project. Feel free to open issues or submit pull requests for improvements.
Donβt forget to βοΈ the repository if you find it useful!
Demo App
Happy coding! π»
Top comments (0)