JSON Server supports advanced querying out of the box:
GET /posts?views:gt=100 # Filter by condition
GET /posts?_sort=-views # Sort by field (descending)
GET /posts?_page=1&_per_page=10 # Pagination
GET /posts?_embed=comments # Include relations
GET /posts?_where={"or":[...]} # Complex queries
See detailed documentation below for each feature.
Routes
Array Resources
For array resources like posts and comments:
GET /posts
GET /posts/:id
POST /posts
PUT /posts/:id
PATCH /posts/:id
DELETE /posts/:id
Object Resources
For singular object resources like profile:
GET /profile
PUT /profile
PATCH /profile
Query params
Conditions
Use field:operator=value.
Operators:
no operator -> eq (equal)
lt less than, lte less than or equal
gt greater than, gte greater than or equal
eq equal, ne not equal
in included in comma-separated list
contains string contains (case-insensitive)
startsWith string starts with (case-insensitive)
endsWith string ends with (case-insensitive)
Examples:
GET /posts?views:gt=100
GET /posts?title:eq=Hello
GET /posts?id:in=1,2,3
GET /posts?author.name:eq=typicode
GET /posts?title:contains=hello
GET /posts?title:startsWith=Hello
GET /posts?title:endsWith=world
Sort
GET /posts?_sort=title
GET /posts?_sort=-views
GET /posts?_sort=author.name,-views
JSON-Server
Install
Usage
Create a
db.jsonordb.json5fileView db.json5 example
You can read more about JSON5 format here.
Start JSON Server
This starts the server at
http://localhost:3000. You should see:Access your REST API:
Response:
Run
json-server --helpfor a list of optionsSponsors ✨
Gold
Silver
Bronze
Become a sponsor and have your company logo here
Query Capabilities
JSON Server supports advanced querying out of the box:
See detailed documentation below for each feature.
Routes
Array Resources
For array resources like
postsandcomments:Object Resources
For singular object resources like
profile:Query params
Conditions
Use
field:operator=value.Operators:
eq(equal)ltless than,lteless than or equalgtgreater than,gtegreater than or equaleqequal,nenot equalinincluded in comma-separated listcontainsstring contains (case-insensitive)startsWithstring starts with (case-insensitive)endsWithstring ends with (case-insensitive)Examples:
Sort
Pagination
Response:
Notes:
_per_pagedefaults to10if not specified_pageor_per_pagevalues are automatically normalized to valid rangesEmbed
Complex filter with
_where_whereaccepts a JSON object and overrides normal query params when valid.Delete dependents
Static Files
JSON Server automatically serves files from the
./publicdirectory.To serve additional static directories:
Static files are served with standard MIME types and can include HTML, CSS, JavaScript, images, and other assets.
Migration Notes (v0 → v1)
If you are upgrading from json-server v0.x, note these behavioral changes:
idis always a string and will be auto-generated if not provided_per_pagewith_pageinstead of the deprecated_limitparameter_embedinstead of_expandfor including related resources--delayCLI option