Database.json -

import json new_post = {"id": 1, "title": "Hello from Python", "content": "Writing to JSON is easy!"} # Load existing data with open('database.json', 'r+') as file: db = json.load(file) db['posts'].append(new_post) # Seek to start and overwrite file.seek(0) json.dump(db, file, indent=2) Use code with caution. Copied to clipboard Best Practices for database.json

You can now send a POST request to http://localhost:3000/posts using fetch in JavaScript: javascript database.json

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": import json new_post = {"id": 1, "title": "Hello

Create a database.json with an initial structure: { "posts": [] } Use code with caution. Copied to clipboard Add the new post db