{"id":13402,"library":"json-server","title":"JSON-Server","description":"json-server is a lightweight Node.js tool for rapidly creating a full fake REST API from a JSON or JSON5 file, requiring virtually no coding. It is currently in active development with a `v1.0.0-beta.x` series (current: `v1.0.0-beta.15`), and new beta versions are released frequently, sometimes multiple times a week, as features are added and fixes applied. The last stable release is `v0.17.4`. Its primary differentiation lies in its simplicity and speed, making it an ideal choice for frontend development prototyping, mobile app mocking, and quick testing environments where a real backend is not yet available or too complex to set up. It automatically handles typical REST operations (GET, POST, PUT, PATCH, DELETE) and supports advanced features like filtering, sorting, pagination, and relationships based on the structure of the provided data file.","status":"active","version":"1.0.0-beta.15","language":"javascript","source_language":"en","source_url":"https://github.com/typicode/json-server","tags":["javascript","JSON","server","fake","REST","API","prototyping","mock","mocking"],"install":[{"cmd":"npm install json-server","lang":"bash","label":"npm"},{"cmd":"yarn add json-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-server","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is the default import for programmatic usage, providing methods like `create`, `router`, and `defaults`.","wrong":"import { jsonServer } from 'json-server';","symbol":"jsonServer","correct":"import jsonServer from 'json-server';"},{"note":"These methods are properties of the default `jsonServer` import, not direct named exports.","wrong":"import { create, router, defaults } from 'json-server';","symbol":"create, router, defaults","correct":"import jsonServer from 'json-server';\nconst server = jsonServer.create();"},{"note":"The `npx` command is the recommended way to execute JSON-Server without global installation, using the version installed in `node_modules`.","wrong":"node json-server db.json","symbol":"CLI","correct":"npx json-server db.json"}],"quickstart":{"code":"import jsonServer from 'json-server';\nimport path from 'path';\n\nconst server = jsonServer.create();\nconst router = jsonServer.router(path.join(__dirname, 'db.json'));\nconst middlewares = jsonServer.defaults();\n\n// Set default middlewares (logger, static, cors and no-cache)\nserver.use(middlewares);\n\n// Add custom routes before JSON Server router\nserver.get('/echo', (req, res) => {\n  res.json(req.query);\n});\n\nserver.use(router);\nserver.listen(3000, () => {\n  console.log('JSON Server is running on http://localhost:3000');\n});\n\n// Example db.json content\n// {\n//   \"posts\": [ { \"id\": \"1\", \"title\": \"json-server\", \"author\": \"typicode\" } ]\n// }","lang":"typescript","description":"Demonstrates how to start JSON Server programmatically with a `db.json` file, applying default middleware, adding a custom route, and listening on port 3000."},"warnings":[{"fix":"Refer to the latest changelog and documentation for `v1.x` updates. For a stable version, consider `v0.17.4`.","message":"Version 1.x is currently in beta. Expect frequent breaking changes and API adjustments before the stable release. Functionality and behaviors may change without prior notice.","severity":"breaking","affected_versions":">=1.0.0-beta.0"},{"fix":"Refactor existing queries to use `_where` for advanced filtering and standard `_page`, `_limit` parameters for pagination. For example, use `_page=1&_limit=10` instead of `_start=0&_end=10`.","message":"Query parameters `_start`, `_end`, and `_limit` have been dropped in `v1.0.0-beta.6` in favor of a new `_where` filtering operator and standard `_page`, `_limit` for pagination.","severity":"breaking","affected_versions":">=1.0.0-beta.6"},{"fix":"Do not rely on incremental numeric IDs; treat IDs as opaque strings. When creating new resources (POST), omit the `id` field from the request body or be aware it will be ignored in favor of a server-generated ID.","message":"Resource IDs generated by the server now use `base64url` random IDs instead of incremental numbers, and client-provided IDs for new resources are ignored.","severity":"breaking","affected_versions":">=1.0.0-beta.14"},{"fix":"Use the `.json5` extension for files formatted with JSON5 syntax. For `.json` files, ensure strict JSON validity. `json-server` can automatically insert a `$schema` reference upon startup if missing.","message":"JSON-Server now supports both `db.json` and `db.json5` files. When using `.json` files, strict JSON parsing is applied, and invalid syntax will cause errors.","severity":"gotcha","affected_versions":">=1.0.0-beta.5"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your request body is valid JSON. Since `v1.0.0-beta.13`, `json-server` returns a `400 Bad Request` error for invalid JSON bodies, providing clearer feedback.","cause":"Sending malformed JSON in POST/PUT/PATCH requests to the server.","error":"Invalid JSON request body"},{"fix":"Update `json-server` to `v1.0.0-beta.15` or newer. This version fixes the behavior to return JSON responses for 404 errors, aligning with typical API expectations.","cause":"Prior to `v1.0.0-beta.15`, 404 error responses were returned as plain text by default.","error":"404 Not Found response is plain text, not JSON."},{"fix":"Remove the `id` field from the request body when creating new resources via POST. Rely on the server to generate and return the `id` in the response for the newly created resource.","cause":"Since `v1.0.0-beta.14`, `json-server` ignores client-provided `id` fields in POST requests and generates its own unique `base64url` ID.","error":"Client-provided ID is not honored when creating a new resource (POST)."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"json-server","cli_version":null}