How can I update a JSON file using fetch?

seanolad profile image Sean ใƒป1 min read


I just started using fetch to make requests over http. I used to use axios, but I don't any more. I need to make changes to the json file using fetch, but I don't know how. What can I do?


markdown guide

TL;DR: You need some form of server side code to update the file.

First, you need to understand what you are doing. You have a client-server application, where the server is sending you that JSON file (wether it is a static file on a folder, or something more dynamic using PHP, Node, Python, etc.) and the client (your browser maybe?) is doing something with that JSON.

As you already noticed, whenever you change the JSON it is not persisted because it is just a copy on your browser, so, you need to ask the server to persist these changes.

This action (updating a file in a server) is a fairly simple operation, the difficult part is understanding (as @mxldevs briefly mentions) what you are doing and why.

We cannot just say use x.y to save the file if we do not even understand what you are doing and how.


Take a step back. What are you trying to accomplish and why do you feel fetch is the appropriate tool for the job?