Is storing data in a file (data.json) a good idea?

I want to store JSON-objects in a data.json file (which is a JSON-array) and get this data by usind the fs module. So my question is if this is a good idea or should i go for using a database (I’m not sure if this is too “heavy” for a small application) ?


That’s for you to decide. Databases are more secure, but they also take more work (unless you already know everything about a database, you’re going to need to learn how to interact with it). Storing data in plain text also allows users to view or edit it directly, which could be an advantage or a disadvantage depending on your use case.

If you’re honestly not sure, it’s most likely easier to transition from writing to .json files to writing to a database than transitioning between unlike databases, so starting with file-saving could be a good measure to test your logic with output you can easily see and then transition to a database if you desire.

thanks for your answer :slight_smile: yeah I’m not really sure what to use, because I don’t need any queries and so on, I always need all of my data (all the objects in the JSON-array) for my purposes

Hi, I’m a bit late to the thread,
What I’m doing is storing compressed json strings in files, using zlib.
Not an expert, but I believe that when the data doesn’t store critical information, like passwords, this is just enough to ‘hide’ plain text so that users don’t touch it, while easily loading the data.

Does that seem like a good idea?

Having your data in an archive is usually enough to keep your average user out and signal to your above-average user that if they choose to meddle with the data they might cause undesired side effects within the software. If there’s nothing there that a hacker could use to compromise someone’s computer and all you need is to keep an amateur who can barely navigate Notepad from changing things and forgetting about it, that’s fine.

1 Like