You’re building a frontend, but the backend isn’t ready. You need a REST API that returns realistic JSON right now, with working GET, POST, PUT, and DELETE, so you can keep coding instead of waiting.
That’s what json-server is for. Point it at a single JSON file and it serves a full REST API in seconds, no backend code required. Its sibling, JSONPlaceholder, goes one step further: a hosted fake API you can call without installing anything. This guide shows how to use both, where they run out of road, and when to move up to a schema-aware mock in Apidog.
For the bigger picture on faking endpoints, see what a mock API is. Here we focus on the two tools developers reach for first.
What is json-server?
json-server is an open-source npm tool that turns a plain JSON file into a real REST API. You write a db.json file describing your resources, run one command, and you get standard CRUD routes backed by that file. Write requests actually modify the file, so the data persists between requests during your session.
It’s the fastest way to get a working API for prototyping, frontend development, demos, and tests, without standing up a database or writing server code. The project lives on GitHub and is widely used for exactly this job.
Install and run json-server
Install it from npm:
npm install json-server
Create a db.json file in your project. Top-level array keys become collection routes; top-level objects become single-resource routes:
{
"posts": [
{ "id": "1", "title": "First post", "views": 100 },
{ "id": "2", "title": "Second post", "views": 250 }
],
"comments": [
{ "id": "1", "text": "Nice work", "postId": "1" }
],
"profile": {
"name": "apidog"
}
}
Start the server:
npx json-server db.json
It runs at http://localhost:3000 by default. That’s it; you now have a live API.
Note on versions: json-server v1 dropped the old--watchflag, sonpx json-server db.jsonis the current command. If you’re on the older 0.x line you’ll still seejson-server --watch db.jsonin tutorials.
The routes you get for free
From the db.json above, json-server generates a complete REST surface.
For the posts array:
GET /posts
GET /posts/:id
POST /posts
PUT /posts/:id
PATCH /posts/:id
DELETE /posts/:id
For the profile object:
GET /profile
PUT /profile
PATCH /profile
Querying is built in too. The v1 syntax uses a colon for conditions:
GET /posts?views:gt=100 # views greater than 100
GET /posts?views:lte=50 # views less than or equal to 50
GET /posts?_sort=-views # sort by views, descending
GET /posts?_page=1&_per_page=25 # pagination
GET /posts?_embed=comments # include related comments
Available operators include lt, lte, gt, gte, eq, ne, in, contains, startsWith, and endsWith. For a flat file and one command, that’s a lot of API.
JSONPlaceholder: a fake API with zero setup
Sometimes you don’t even want to install a tool. JSONPlaceholder, from the same author, is a free fake REST API hosted at jsonplaceholder.typicode.com. You call it straight from your code:
curl https://jsonplaceholder.typicode.com/posts/1
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident",
"body": "quia et suscipit..."
}
It ships with six ready-made resources:
/posts(100 items)/comments(500)/albums(100)/photos(5000)/todos(200)/users(10)
It accepts POST, PUT, PATCH, and DELETE too, but here’s the catch: writes are faked. The API returns a realistic response as if the change happened, but nothing is saved. Refresh and your “new” post is gone. That’s fine for wiring up UI code against predictable data; it’s not a real backend.
json-server vs JSONPlaceholder
| json-server | JSONPlaceholder | |
|---|---|---|
| Setup | Install npm package, write db.json |
None, just call the URL |
| Runs | Locally, your machine | Hosted, public |
| Custom data | Yes, your own resources | No, fixed resources |
| Writes persist | Yes, to db.json |
No, faked |
| Best for | Prototyping with your own shapes | Quick demos and learning |
Reach for JSONPlaceholder when you want data this minute and don’t care what it is. Reach for json-server when you need your own resources and writes that stick.
Where these tools run out of road
json-server and JSONPlaceholder are excellent at one thing: serving JSON fast. They start to hurt once a project grows past a solo prototype.
- No real validation. They don’t enforce a schema. Post a string where a number belongs and it’s happily stored. Your real API would reject it.
- No dynamic or smart data. Responses are whatever sits in the file. There’s no built-in way to return a fresh random email or a date in the future per request.
- Local and single-user. json-server runs on your laptop. A teammate or a CI job can’t hit
localhost:3000. JSONPlaceholder is shared, but you can’t customize it. - Drifts from your spec. The fake data lives in a separate file, disconnected from your OpenAPI contract, so the two drift apart as the API evolves.
- Faked writes (JSONPlaceholder). Anything stateful, like a cart or a multi-step flow, can’t be tested against it.
If you’ve outgrown a flat file, our roundups of tools for mocking REST endpoints and free and cheap API mock servers cover the next tier, and online API mocking tools compared puts the hosted options side by side.
When to move up to a real mock server
A schema-aware mock fixes every limitation above. This is where Apidog takes over from json-server.

- Schema-driven, not file-driven. Define an endpoint (or import your OpenAPI spec) and Apidog mocks it automatically. The mock and the contract stay in sync because they’re the same definition.
- Smart, dynamic data. Apidog reads field names and types and returns realistic values: a valid email for an
emailfield, a date forcreatedAt, a number forprice. You can attach Faker-style rules per field for full control. Our guide to Faker.js in Apidog and the broader test data generator walkthrough go deeper on producing realistic values. - A shareable cloud URL. Apidog gives the mock a hosted URL your whole team and your CI pipeline can call, not just
localhost. - No Node required. There’s no package to install per project and no
db.jsonto babysit.
Mock the same API in Apidog
- Download Apidog and create or open a project.
- Add an endpoint, for example
GET /posts, and define its response schema (or import an existing OpenAPI file). - Apidog generates a mock URL and starts returning smart, realistic data for every field right away.
- Need specific values? Add a mock rule per field to pin the output.
- Share the mock URL with your team or drop it into your test suite and CI.

You keep the “API in minutes” speed of json-server, and you gain validation, dynamic data, and a URL everyone can reach.
FAQ
Is json-server free? Yes, it’s open source and free to use. JSONPlaceholder is free too.
Does json-server persist data? Yes. POST, PUT, PATCH, and DELETE write back to your db.json, so changes survive between requests while the server runs. JSONPlaceholder fakes writes and saves nothing.
Can I use json-server in production? No. It’s built for prototyping and testing. It has no real validation, auth, or scalability story.
What’s the difference between json-server and a mock server like Apidog? json-server serves a static file as an API. Apidog mocks from your API schema, returns dynamic realistic data, and exposes a shared cloud URL. See what a mock API is and the REST mocking tools roundup for context.
How do I get realistic fake data instead of static rows? Use a generator. A test data generator creates varied, realistic records, and Apidog’s mock does this automatically from your schema.
The short version
json-server turns a JSON file into a working REST API with one command, and JSONPlaceholder gives you a hosted fake API with no setup at all. Both are perfect for getting unblocked fast. Once you need schema validation, dynamic data, persistent state, and a URL your team can actually reach, a flat file isn’t enough. That’s the line where Apidog’s mock server takes over. Download Apidog, import your spec, and your mock matches the real contract from the first request.



