|
| 1 | +--- |
| 2 | +title: Why JSON is unsuitable as a database |
| 3 | +description: The many reasons why you shouldn't use JSON as a database, and instead opt for SQL. |
| 4 | +relevant_links: |
| 5 | + Tips on Storing Data: https://tutorial.vcokltfre.dev/tips/storage/ |
| 6 | +--- |
| 7 | + |
| 8 | +JSON, quite simply, is not a database. It's not designed to be a data storage format, |
| 9 | +rather a wayof transmitting data over a network. It's also often used as a way of doing configuration files for programs. |
| 10 | + |
| 11 | +There is no redundancy built in to JSON. JSON is just a format, and Python has libraries for it |
| 12 | +like json and ujson that let you load and dump it, sometimes to files, but that's all it does, write data to a file. |
| 13 | +There is no sort of DBMS (Database Management System), which means no sort of sophistication in how the data is stored, |
| 14 | +or built in ways to keep it safe and backed up, there's no built in encryption either - bear in mind |
| 15 | +in larger applications encryption may be necessary for GDPR/relevant data protection regulations compliance. |
| 16 | + |
| 17 | +JSON, unlike relational databases, has no way to store relational data, |
| 18 | +which is a very commonly needed way of storing data. |
| 19 | +Relational data, as the name may suggest, is data that relates to other data. |
| 20 | +For example if you have a table of users and a table of servers, the server table will probably have an owner field, |
| 21 | +where you'd reference a user from the users table. (**This is only relevant for relational data**). |
| 22 | + |
| 23 | +JSON is primarily a KV (key-value) format, for example `{"a": "b"}` where `a` is the key and `b` is the value, |
| 24 | +but what if you want to search not by that key but by a sub-key? Well, instead of being able to quickly use `var[key]`, |
| 25 | +which in a Python dictionary has a constant return time (for more info look up hash tables), |
| 26 | +you now have to iterate through every object in the dictionary and compare to find what you're looking for. |
| 27 | +Most relational database systems, like MySQL, MariaDB, and PostgreSQL have ways of indexing secondary fields |
| 28 | +apart from the primary key so that you can easily search by multiple attributes. |
0 commit comments