typicode

    typicode/json-server

    #305 this week

    Get a full fake REST API with zero coding in less than 30 seconds (seriously)

    api
    frontend
    testing
    fake
    json
    mock
    rest
    test
    JavaScript
    MIT
    75.7K stars
    7.3K forks
    75.7K GitHub watchers
    Updated 7/15/2026
    View on GitHub

    Backblaze Generative Media Hackathon

    Build the next generation of AI media apps with Genblaze, stored on Backblaze B2. $10,000 in prizes.

    Enter the hackathon

    Loading star history...

    Use Cases & Benefits

    • json-server provides a full fake REST API with zero coding, ideal for rapid prototyping and frontend development.
    • Built with JavaScript, it supports JSON/JSON5 data files and offers RESTful routes with filtering, pagination, sorting, and embedding.
    • Strengths include ease of use, quick setup, and extensive query capabilities; limitations include being a mock server not for production data persistence.
    • Organizations can use json-server in development and testing environments to simulate backend APIs, accelerating frontend integration and testing.
    • Ideal use cases are frontend development, API prototyping, testing, and demos where a quick, configurable REST API is needed without backend coding.

    About json-server

    json-server

    Node.js CI

    [!IMPORTANT] Viewing beta v1 documentation – usable but expect breaking changes. For stable version, see here

    👋 Hey! Using React, Vue or Astro? Check my new project MistCSS to write 50% less code.

    Install

    npm install json-server
    

    Usage

    Create a db.json or db.json5 file

    {
      "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.json
    

    Get 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

    Sponsors ✨

    Sponsors
    Sponsors
    Sponsors
    Delivery Routing Software and Route Optimization Software

    Become a sponsor and have your company logo here

    Sponsorware

    [!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/.

    Routes

    Based on the example db.json, you'll get the following routes:

    GET    /posts
    GET    /posts/:id
    POST   /posts
    PUT    /posts/:id
    PATCH  /posts/:id
    DELETE /posts/:id
    
    # Same for comments
    
    GET   /profile
    PUT   /profile
    PATCH /profile
    

    Params

    Conditions

    • ==
    • lt<
    • lte<=
    • gt>
    • gte>=
    • ne!=
    GET /posts?views_gt=9000
    

    Range

    • start
    • end
    • limit
    GET /posts?_start=10&_end=20
    GET /posts?_start=10&_limit=10
    

    Paginate

    • page
    • per_page (default = 10)
    GET /posts?_page=1&_per_page=25
    

    Sort

    • _sort=f1,f2
    GET /posts?_sort=id,-views
    

    Nested and array fields

    • x.y.z...
    • x.y.z[i]...
    GET /foo?a.b=bar
    GET /foo?x.y_lt=100
    GET /foo?arr[0]=bar
    

    Embed

    GET /posts?_embed=comments
    GET /comments?_embed=post
    

    Delete

    DELETE /posts/1
    DELETE /posts/1?_dependent=comments
    

    Serving static files

    If you create a ./public directory, JSON Server will serve its content in addition to the REST API.

    You can also add custom directories using -s/--static option.

    json-server -s ./static
    json-server -s ./static -s ./node_modules
    

    Notable differences with v0.17

    • id is always a string and will be generated for you if missing
    • use _per_page with _page instead of _limitfor pagination
    • use Chrome's Network tab > throtling to delay requests instead of --delay CLI option

    Discover Repositories

    Search across tracked repositories by name or description