Jump to content

Database.json Online

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

In your terminal, run: npx json-server --watch database.json database.json

If you want to treat database.json like a real REST API, json-server is the standard choice. import json new_post = {"id": 1, "title": "Hello

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated