This is not something that json-server supports natively, as far as I know, but it can be accomplished through a workaround.

I am assuming that you have some prior knowledge of node.js

You will have to create a server.js file which you will then run using node.js. The server.js file will then make use of the json-server module.

I have included the code for the server.js file in the code snippet below.

I made use of lodash for my duplicate check. You will thus need to install lodash. You can also replace it with your own code if you do not want to use lodash, but lodash worked pretty well in my opinion.

The server.js file includes a custom post request function which accesses the lowdb instance used in the json-server instance. The data from the POST request is checked for duplicates and only new records are added to the DB where the id does not already exist. The write() function of lowdb persists the data to the db.json file. The data in memory and in the file will thus always match.

Please note that the API endpoints generated by json-server (or the rewritten endpoints) will still exist. You can thus use the custom function in conjunction with the default endpoints.

Feel free to add error handling where needed.

const jsonServer = require('json-server');
const server = jsonServer.create();
const _ = require('lodash')
const router = jsonServer.router('./db.json');
const middlewares = jsonServer.defaults();
const port = process.env.PORT || 3000;
    
server.use(middlewares);
server.use(jsonServer.bodyParser)
server.use(jsonServer.rewriter({
    '/api/products': '/products'
}));
    
server.post('/api/productcollection', (req, res) => {
    const db = router.db; // Assign the lowdb instance
    
    if (Array.isArray(req.body)) {
        req.body.forEach(element => {
            insert(db, 'products', element); // Add a post
        });
    }
    else {
        insert(db, 'products', req.body); // Add a post
    }
    res.sendStatus(200)
    
    /**
     * Checks whether the id of the new data already exists in the DB
     * @param {*} db - DB object
     * @param {String} collection - Name of the array / collection in the DB / JSON file
     * @param {*} data - New record
     */
    function insert(db, collection, data) {
        const table = db.get(collection);
        if (_.isEmpty(table.find(data).value())) {
            table.push(data).write();
        }
    }
});
    
server.use(router);
server.listen(port);

If you have any questions, feel free to ask.

Answer from Ruan on Stack Overflow
🌐
GitHub
github.com › typicode › json-server
GitHub - typicode/json-server: Get a full fake REST API with zero coding in less than 30 seconds (seriously) · GitHub
February 20, 2026 - { "$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 ·
Starred by 75.7K users
Forked by 7.3K users
Languages   JavaScript 91.7% | HTML 8.3%
🌐
DEV Community
dev.to › ldakanno › making-a-post-request-using-json-server-h7c
Making a POST request using json-server - DEV Community
December 11, 2022 - Once your json-server is set up and has some data, you are going to create a basic POST request. There are a few requirements to make a post request. Alongside the URL you will be posting to, you need to also have a configuration object that will pretty much explain what the post request will be. For visual aid, here is a basic example ...
🌐
npm
npmjs.com › package › json-server
json-server - npm
3 days ago - { "$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 ·
      » npm install json-server
    
Published   Mar 13, 2026
Version   1.0.0-beta.13
Author   typicode
🌐
ReqBin
reqbin.com › req › 4rwevrqh › post-json-example
How do I post JSON to the server?
The following is an example of sending JSON data to ReqBin echo URL. ... POST /echo/post/json HTTP/1.1 Host: reqbin.com Accept: application/json Content-Type: application/json Content-Length: 81 { "Id": 78912, "Customer": "Jason Sweet", "Quantity": ...
Top answer
1 of 3
5

This is not something that json-server supports natively, as far as I know, but it can be accomplished through a workaround.

I am assuming that you have some prior knowledge of node.js

You will have to create a server.js file which you will then run using node.js. The server.js file will then make use of the json-server module.

I have included the code for the server.js file in the code snippet below.

I made use of lodash for my duplicate check. You will thus need to install lodash. You can also replace it with your own code if you do not want to use lodash, but lodash worked pretty well in my opinion.

The server.js file includes a custom post request function which accesses the lowdb instance used in the json-server instance. The data from the POST request is checked for duplicates and only new records are added to the DB where the id does not already exist. The write() function of lowdb persists the data to the db.json file. The data in memory and in the file will thus always match.

Please note that the API endpoints generated by json-server (or the rewritten endpoints) will still exist. You can thus use the custom function in conjunction with the default endpoints.

Feel free to add error handling where needed.

const jsonServer = require('json-server');
const server = jsonServer.create();
const _ = require('lodash')
const router = jsonServer.router('./db.json');
const middlewares = jsonServer.defaults();
const port = process.env.PORT || 3000;
    
server.use(middlewares);
server.use(jsonServer.bodyParser)
server.use(jsonServer.rewriter({
    '/api/products': '/products'
}));
    
server.post('/api/productcollection', (req, res) => {
    const db = router.db; // Assign the lowdb instance
    
    if (Array.isArray(req.body)) {
        req.body.forEach(element => {
            insert(db, 'products', element); // Add a post
        });
    }
    else {
        insert(db, 'products', req.body); // Add a post
    }
    res.sendStatus(200)
    
    /**
     * Checks whether the id of the new data already exists in the DB
     * @param {*} db - DB object
     * @param {String} collection - Name of the array / collection in the DB / JSON file
     * @param {*} data - New record
     */
    function insert(db, collection, data) {
        const table = db.get(collection);
        if (_.isEmpty(table.find(data).value())) {
            table.push(data).write();
        }
    }
});
    
server.use(router);
server.listen(port);

If you have any questions, feel free to ask.

2 of 3
1

It probably didn't work at the time when this question was posted but now it does, call with an array on the /products endpoint for bulk insert.

🌐
ZetCode
zetcode.com › javascript › jsonserver
JSON Server Tutorial - Creating Fake REST APIs
Learn how to use JSON Server in JavaScript to create fake REST APIs, with examples and best practices.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-post-json-data-to-server
How to Post JSON Data to Server ? - GeeksforGeeks
August 1, 2024 - When the user hits the send button it makes a POST request with JSON data to the /data route on the server, and then the server logs the received data. Example: In this example, we will make use of fetch API to send data to the NodeJS server.
🌐
Stack Overflow
stackoverflow.com › questions › 75592483 › how-to-post-a-request-with-jsonapi-compliant-data-to-json-server
reactjs - How to post a request with JSON:API compliant data to json server? - Stack Overflow
Copy{ "data": [ { "type": "posts", "id": "1", "attributes": { "title": "First post", "content": "This is my first post" } }, { "type": "posts", "id": "2", "attributes": { "title": "Second post", "content": "This is my second post" } } ] } Whenever ...
Find elsewhere
🌐
YouTube
youtube.com › watch
JSON Server Tutorial - 9 - POST Request - YouTube
📘 Courses - https://learn.codevolution.dev/💖 Support UPI - https://support.codevolution.dev/💖 Support PayPal - https://www.paypal.me/Codevolution💾 Github...
Published   November 15, 2021
🌐
SitePoint
sitepoint.com › blog › javascript › json server example
JSON Server Example — SitePoint
February 12, 2024 - JSON Server supports filtering data using query parameters. For example, if you want to get all posts with the title “Hello World”, you would send a GET request to /posts?title=Hello World.
🌐
Stack Overflow
stackoverflow.com › questions › 69315079 › how-to-add-data-into-json-server-database
How to add data into json-server database - javascript
async function postData(url = '', data = {}) { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) return response.json() }
🌐
W3Schools
w3schools.com › js › js_json_server.asp
JSON Server
When receiving data from a web server, the data is always a string. Parse the data with JSON.parse(), and the data becomes a JavaScript object. If you have data stored in a JavaScript object, you can convert the object into JSON, and send it to a server:
🌐
DigitalOcean
digitalocean.com › community › tutorials › json-server
JSON Server (json-server) | DigitalOcean
August 4, 2022 - Please take in account that for Windows the single quote character did not work and I ended up escaping the double quote: curl -X POST -H “Content-Type: application/json” -d “{\“id\”: 3, \“name\”: \“Lisa\”, \“salary\”: \“2000\”}” “https://localhost:3000/employees” Cheers
🌐
GitHub
github.com › typicode › json-server › issues › 453
Is it possible to 'get' data using POST with json-server? · Issue #453 · typicode/json-server
January 11, 2017 - Hi, I am trying to get response using POST. My POST body has some key-value pairs which determine what needs to be responded. Is it possible to get data back from POST method ? Thanks
Author   vsharma2266
🌐
freeCodeCamp
freecodecamp.org › news › json-server-for-frontend-development
How to Use JSON Server for Front-end Development
August 21, 2023 - POST /users - This creates a new user. PUT /users/:id - This updates a user based on a specified id. DELETE /users/:id - This deletes a user based on the specified id. This pattern makes it easy to interact with the mock API in a RESTful manner ...
🌐
Keyhole Software
keyholesoftware.com › home › mock restful servers fast with json server
Mock a RESTful Server With JSON Server Quickly and Easily
June 23, 2025 - For example, let’s send a POST request to http://localhost:4000/subjects with the following body (note: in Postman, make sure to select the “raw” radio button and select “JSON” from the dropdown menu):
🌐
LogRocket
blog.logrocket.com › home › how to bootstrap your project with json server
How to bootstrap your project with JSON Server - LogRocket Blog
June 4, 2024 - We’ll tell the json-server command to watch our db.json configuration file. ... You can verify that your server is running by sending a GET request to http://localhost:3000/authors/1. If it returns a result, you are ready to explore other endpoints. We can send a POST request via Postman or curl.
🌐
Medium
medium.com › cbazil-dev › setting-up-a-quick-json-server-restful-api-e5535685c223
Setting up a quick JSON server (RESTful API) | by Chad Bosch | Cbazil.Dev | Medium
March 23, 2022 - ... Using the URL http://localhost:3000/users, Use the POST request in POSTMAN to post new data. In the header tab you’ll need to add “Content-type : application/json” to join our body fields as we post data to our database.
🌐
JSONPlaceholder
jsonplaceholder.typicode.com
JSONPlaceholder - Free Fake REST API
JSONPlaceholder comes with a set of 6 common resources: Note: resources have relations. For example: posts have many comments, albums have many photos, ... see guide for the full list. All HTTP methods are supported. You can use http or https for your requests. Note: see guide for usage examples. With our sponsor Mockend and a simple GitHub repo, you can have your own fake online REST server ...
🌐
DhiWise
dhiwise.com › post › how-to-use-json-server-in-frontend-development
A Complete Guide to Using JSON Server in Frontend Development
February 1, 2024 - In this example, "users" and "posts" are resources; each object within the array is a record. To generate sample data for interactive application from the JSON database, you can manually create records in the JSON file or use a tool to generate fake data.