Problems with JSON


#1

Hey, I have problems with saving data to JSON, Glitch randomly wipes data from JSON and removes everything from it :confused: How can I solve it ?


#2

Are you saving data to a .json file, or just to a variable in your project? If you let us know your project name, we can take a look.


#3

I’m saving variable to from project to JSON object, project name is pixelbot-v1 (You’re already in), problem is with startPixel() method in index.js


#4

Ok, so you’re reading and writing data to and from a file and the syntax of that looks ok. My hunch is that it’s a problem with the timings of when you’re reading/writing to the file because you have multiple nested setInterval and setTimeout functions and any project restarts, like when you’re working on the code could interrupt that too.

I recommend looking at using something like low-db (https://glitch.com/~low-db), which uses JSON files on the filesystem as a simple database. It will allow you more control over manipulating the content of the file such that you won’t accidentally overwrite your data.


#5

Question, how can I remove object from lowdb


#6

Docs are here: https://github.com/typicode/lowdb - you can see a couple of options for removing data.


#7

Thank you Gareth!

It works with LowDB, thank you for fast answer and solution, thanks for helping always :stuck_out_tongue:

Best regards from Poland, John :wink: