DEV Community

loading...

How can I update a JSON file using fetch?

Sean
Hi, name's Sean.
ใƒป1 min read

Fetch

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?

Discussion (2)

Collapse
eruizdechavez profile image
Erick Ruiz de Chavez

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.

Collapse
mxldevs profile image
MxL Devs

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

Forem Open with the Forem app