9/18 | Validate feature ideas earlier with AI-driven prototypes

What are best AI tools? Take the State of AI survey

Builder.io
Builder.io
Contact sales

9/18 | Validate feature ideas earlier with AI-driven prototypes

What are best AI tools? Take the State of AI survey

Builder.io
Builder.io
< Back to blog

AI

Rapid Mock API creation with ChatGPT and json-server

May 3, 2023

Written By Vishwas Gopinath

As front-end developers, we often require mock data to swiftly build prototypes. We could create a JSON file with gibberish data but creating fake data can be time-consuming and ineffective. Also, reading data from a file is not how real apps operate. In this blog post, we'll discuss how you can create mock APIs for UI prototyping in 10 minutes. That’s right, 10 minutes!

The challenges of mock data generation

Generating sample data is no easy feat. Defining a schema for an entity and generating placeholder data can be a daunting task. For instance, coming up with a list of product names for an e-commerce website can be challenging. Should the product names be descriptive or catchy? How many characters should they have? Should they be in uppercase or lowercase?

If we struggle to come up with a single variable name, I’m sure we will struggle to come up with an entire dataset. Moreover, generating a dataset is not a one-time task. As the application evolves, the dataset will have to be updated and adjusted, which can be a tedious process.

Creating an API endpoint as a front-end developer can be challenging as well, and advanced features like sorting, filtering, and pagination necessitate further effort. Proper server-side implementation is required to handle POST, PATCH, and DELETE requests.

This can be daunting for front-end developers who have limited experience in backend development. It's essential to have a solid understanding of RESTful API principles to create a well-designed API endpoint.

The Solution: ChatGPT and json-server

Fortunately, there is a solution to both of these challenges: ChatGPT and json-server. ChatGPT is a powerful tool that can help generate sample data with ease. json-server is a powerful library that can be used to create a fake REST API with zero coding. Let’s dive into the details.

Generating sample data using ChatGPT

One of the best use cases for ChatGPT is the generation of sample data. Here's how you can generate a schema for an entity, like a product on an e-commerce site.

Prompt: Give me a list of 5 fields for electronic products on an e-commerce site.

ChatGPT Response:
Sure, here are five fields for electronic products that you could use on an e-commerce site:
1. Category: This field could be used to group electronic products into different categories, such as smartphones, laptops, cameras, gaming devices, and home appliances.
2. Brand: This field could be used to identify the brand of the electronic product, such as Apple, Samsung, HP, Canon, and LG.
3. Model: This field could be used to identify the specific model of the electronic product, such as iPhone 12, Galaxy S21, MacBook Pro, EOS Rebel T7i, and OLED65C1.
4. Features: This field could be used to list the key features of the electronic product, such as display size, camera resolution, battery life, storage capacity, and connectivity options.
5. Price: This field could be used to display the price of the electronic product, either as a fixed price or a price range depending on the options selected.

You can ask ChatGPT to add or remove a few fields by modifying the prompt accordingly.

Prompt: Add an "id" field that will be unique to each productChatGPT.

ChatGPT response: Sure, here's an updated list of fields that includes an "id" field for each electronic product:
1. Id: This field could be used to assign a unique identifier to each electronic product, such as a product code or SKU (stock-keeping unit) number.
2. Category: This field could be used to group electronic products into different categories, such as smartphones, laptops, cameras, gaming devices, and home appliances.
3. Brand: This field could be used to identify the brand of the electronic product, such as Apple, Samsung, HP, Canon, and LG.
4. Model: This field could be used to identify the specific model of the electronic product, such as iPhone 12, Galaxy S21, MacBook Pro, EOS Rebel T7i, and OLED65C1.
5. Features: This field could be used to list the key features of the electronic product, such as display size, camera resolution, battery life, storage capacity, and connectivity options.
6. Price: This field could be used to display the price of the electronic product, either as a fixed price or a price range depending on the options selected.Generate a sample JSON of 5 such products with realistic values.

Once you are happy with the fields, you can ask ChatGPT to generate JSON.

Prompt: Generate a sample JSON of 5 such products with realistic values.

Setting up API endpoints with json-server

After obtaining the sample data, json-server can be used to create API endpoints. Start by creating a db.json file in the project root and pasting the sample data from ChatGPT.

Next, install the json-server npm package as a dev dependency:

Finally, add an npm script to run json-server with the sample data:

Running npm run serve-json will create a server on http://localhost:4000 with all the necessary endpoints. Here’s how you can work with the various endpoints:

Routes

Filter

Pass the field name as a query parameter. Use . to access deep properties.

Paginate

Use _page and optionally _limit to paginate returned data. (Our data has only one page).

10 items are returned by default

Sort

Add _sort and _order (ascending order by default).

Works exactly as Array.slice (i.e. _start is inclusive and _end exclusive).

Operators

Add _gte or _lte for getting a range

Add _ne to exclude a value

Add _like to filter (RegExp supported)

Full-text search

Add q

Conclusion

ChatGPT and json-server are powerful tools that can help frontend developers generate mock data and serve it over a RESTful API with ease. With ChatGPT, generating a dataset becomes a breeze, and with json-server, creating a fake RESTful API requires zero coding. Together, they offer a simple yet effective solution for rapid mock API creation and front-end developers can focus on building prototypes quickly and efficiently, without worrying about data generation and API implementation.

Share

Twitter
LinkedIn
Facebook
Share this blog
Copy icon
Twitter "X" icon
LinkedIn icon
Facebook icon

Visually edit your codebase with AI

Using simple prompts or Figma-like controls.

Try it nowGet a demo

Design to Code Automation

A pragmatic guide for engineering leaders and development teams


Continue Reading
design9 MIN
How to generate (actually good) designs with AI
September 17, 2025
AI9 MIN
7 Levels of Context Engineering for Designers
September 16, 2025
Design to Code8 MIN
Git Branching for Designers
September 11, 2025

Product

Visual CMS

Theme Studio for Shopify

Sign up

Login

Featured Integrations

React

Angular

Next.js

Gatsby

Resources

User Guides

Developer Docs

Forum

Blog

Github

Get In Touch

Chat With Us

Twitter

Linkedin

Careers

© 2020 Builder.io, Inc.

Security

Privacy Policy

Terms of Service

Get the latest from Builder.io

By submitting, you agree to our Privacy Policy

  • Fusion

  • Publish

  • Product Updates

  • Design to Code

  • Headless CMS

    Multi-Brand CMS

  • Landing Pages

  • Web Apps

  • Prototypes

  • Marketing Sites

  • Headless Commerce

  • Documentation

  • Fusion Docs

  • Publish Docs

  • Blog

  • Webinars

  • Guides

  • Case Studies

  • Community Forum

  • Partners

  • Affiliate Program

  • CMS Integrations

  • CMS Blueprints

  • Glossary

  • Figma to Code Guide

  • Headless CMS Guide

  • Headless Commerce Guide

  • Composable DXP Guide

  • About

  • Careers

  • Contact Sales

Security

Privacy Policy

SaaS Terms

Compliance

Cookie Preferences

YouTube icon
Github icon
Blsky Icon
Twitter "X" icon
LinkedIn icon
Feed Icon
Gartner Cool Vendor 2024