Important
Viewing beta v1 documentation – usable but expect breaking changes. For stable version, see here
Note
Using React ⚛️ and tired of CSS-in-JS? See MistCSS 👀
npm install json-serverCreate a db.json or db.json5 file
{
"$schema": "./node_modules/json-server/schema.json",
"posts": [
{ "id": "1", "title": "a title", "views": 100 },
{ "id": "2", "title": "another title", "views": 200 }
],
"comments": [
{ "id": "1", "text": "a comment about post 1", "postId": "1" },
{ "id": "2", "text": "another comment about post 1", "postId": "1" }
],
"profile": {
"name": "typicode"
}
}View db.json5 example
{
posts: [
{ id: "1", title: "a title", views: 100 },
{ id: "2", title: "another title", views: 200 },
],
comments: [
{ id: "1", text: "a comment about post 1", postId: "1" },
{ id: "2", text: "another comment about post 1", postId: "1" },
],
profile: {
name: "typicode",
},
}You can read more about JSON5 format here.
Pass it to JSON Server CLI
$ npx json-server db.jsonGet a REST API
$ curl http://localhost:3000/posts/1
{
"id": "1",
"title": "a title",
"views": 100
}Run json-server --help for a list of options
![]() |
![]() |
![]() |
Become a sponsor and have your company logo here
Note
This project uses the Fair Source License. Only organizations with 3+ users are kindly asked to contribute a small amount through sponsorship sponsor for usage. This license helps keep the project sustainable and healthy, benefiting everyone.
For more information, FAQs, and the rationale behind this, visit https://fair.io/.
GET /posts?views:gt=100
GET /posts?_sort=-views
GET /posts?_page=1&_per_page=10
GET /posts?_embed=comments
GET /posts?_where={"or":[{"views":{"gt":100}},{"title":{"eq":"Hello"}}]}For array resources (posts, comments):
GET /posts
GET /posts/:id
POST /posts
PUT /posts/:id
PATCH /posts/:id
DELETE /posts/:id
For object resources (profile):
GET /profile
PUT /profile
PATCH /profile
Use field:operator=value.
Operators:
- no operator ->
eq(equal) ltless than,lteless than or equalgtgreater than,gtegreater than or equaleqequal,nenot equal
Examples:
GET /posts?views:gt=100
GET /posts?title:eq=Hello
GET /posts?author.name:eq=typicodeGET /posts?_sort=title
GET /posts?_sort=-views
GET /posts?_sort=author.name,-viewsGET /posts?_page=1&_per_page=25_per_pagedefault is10- invalid page/per_page values are normalized
GET /posts?_embed=comments
GET /comments?_embed=post_where accepts a JSON object and overrides normal query params when valid.
GET /posts?_where={"or":[{"views":{"gt":100}},{"author":{"name":{"lt":"m"}}}]}DELETE /posts/1?_dependent=commentsJSON Server serves ./public automatically.
Add more static dirs:
json-server -s ./static
json-server -s ./static -s ./node_modulesidis always a string and will be generated for you if missing- use
_per_pagewith_pageinstead of_limitfor pagination - use
_embedinstead of_expand - use Chrome's
Network tab > throtlingto delay requests instead of--delayCLI option


