Edit Local JSON File Programmatically

Edit Local JSON File Programmatically
0

#1

So here’s the story:

I’ve got a local, massive .json file that’s quite deep and complicated. Within this file, I need to update an attribute with a URL for stored images. That’s not the part I’m confused about, honestly; I’ve already got working loops to iterate through and edit that value.

The problem is that I don’t know how to make this happen in a way that actually opens the local file, edits it (or rather a copy of it(for safety!)), saves those edits, and gives me back the file I need.

I could just do it manually, copying and pasting the values where they need to go…but there’s about 500 I need to change within the file and I just don’t want to spend 3 hours doing this. Plus I’ll probably need this file-writing at some point in the future.

I’ve done similar things in courses, but always with IDEs that are like training wheels, so doing it in the real world is harder. I’ve tried searching, but hit snags at every turn.

Any help would be appreciated. Thanks!


#2

You can’t read/write local files to disk in plain browser based javascript, but you can if you download and use node.js.


#3

Alright, I’ll check into node.js. Thanks.


#4

It may take you a little time to get up and going with all the intricacies of node.js, which is still worth while to learn imo via the fCC back-end course, but the simplest way to get up and going for your situation maybe using the existing fs module in node … https://www.w3schools.com/nodejs/nodejs_filesystem.asp ,you may also want to import the external path module which makes it easier to navigate around your local system,


#5

Man, thanks a lot. I was actually just reading about the file-system module. I’ll definitely check out the path module because navigating is annoying.

Haven’t done the Back-End stuff yet here, and I’ve got 1 more D3 project to wrap up before I’m done with the Front-End. I appreciate the help and advice!