DEV Community

Htet Ko
Htet Ko

Posted on • Updated on

πŸš€ Introducing dynamic-json-generator: A Powerful Tool for Generating Fake JSON Data!

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

Enter fullscreen mode Exit fullscreen mode

🧩 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);

Enter fullscreen mode Exit fullscreen mode

πŸš€ 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)