Quick question about JSON

Hi @Aprixia :slight_smile:

If you’d like to de-mystify JSON, https://json.org/ is an easy read and fully describes it.

In a nutshell, JSON is a text format which can represent structures (objects, lists, strings, etc).

A JSON file is a text file storing the string of JSON, for example package.json.

A JSON database is a database that can store and retrieve JSON strings. It is much easier to manage than dealing with file locks, etc.

This isn’t correct, a text file can be read, modified and saved. What you’ve likely heard is there can be corruption under certain conditions, if not handled well.

const db = require(`\databases\${message.guild.id}.json`);

require is used to import modules of code. To read JSON files, you’d use file functions the same as for any text file.

So, considering databases, if you have a look at Glitch: The friendly community where everyone builds the web, there are two JSON databases that can be hosted inside the Glitch project, lowdb and NeDB. The storage space will compete with your code space and other files.

An option for hosting outside of the Glitch project is MLAB’s MongoDB, which gives 500MB storage on their free tier. There is even a free course on FreeCodeCamp showing how to connect it all together.

How much data needs to be stored will influence your decision here, have you got some numbers for what you need in dev vs production?

2 Likes