: JSON requires double quotes for keys and string values; single quotes will cause an error.
To write a new entry (a "post") to a database.json file, you can either use a tool like for a quick mock API or write a script in a language like JavaScript (Node.js) or Python to handle the file operations directly. 1. Using json-server (Quickest for Web Devs) database.json
If you want to treat database.json like a real REST API, json-server is the standard choice. : JSON requires double quotes for keys and
const fs = require('fs'); const newPost = { id: Date.now(), title: "Direct Write", content: "Added via fs module" }; // 1. Read the existing file const data = fs.readFileSync('database.json'); const db = JSON.parse(data); // 2. Add the new post db.posts.push(newPost); // 3. Write it back fs.writeFileSync('database.json', JSON.stringify(db, null, 2)); Use code with caution. Copied to clipboard 3. Using Python Python is often used for simple JSON "databases": Using json-server (Quickest for Web Devs) If you
If you aren't using a server and just want to append data to the file locally using Node.js: javascript
In your terminal, run: npx json-server --watch database.json