JSON is just not a database no matter how much you want it to be. It was never meant to manage data, just represent it. If you want to shift from MySQL for performance reasons why not try MongoDB? It’s non-structured manner is pretty performant compared to MySQL. (Don’t quote me on this)
I used to think the two were interchangeable because they were both pretty much ways of storing information, although storing and using JSON files was easier to me at the time. Databases are separate pieces of software that make retrieving data much faster and don’t end up being bloated over time. Also, carrying all the data in one or two files makes it dangerously easy to end up getting your data stolen or lost, where as a database is much more secure with those. Fundamentally, data shouldn’t be part of your code; it should be a separate thing that your code works with.
From stack overflow
MySQL is a database while JSON is not, so the correct answer is MySQL, without hesitation. JSON is just a language, and barely even that. JSON was never designed to handle anything like concurrent connections or any sort of data manipulation, since its own function is to represent data, not to manage it.
So go with MySQL for storing the data. Then you should use some programming language to read that database, and send that information as JSON, rather than actually storing anything in JSON.
If you store the data in files, whether in JSON format or anything else, you will have all sorts of problems that people have stopped worrying about since databases started being used for the same thing. Size limitations, locks, name it. It’s good enough when you have one user, but the moment you add more of them, you’ll start solving so many problems that you would probably end up by writing an entire database engine just to handle the files for you, while all along you could have simply used an actual database.
Great idea but I can’t imagine this being scalable even one bit. Imagine having even just 200+ players.
In the case of +200 players, this system’s failure is apparent.
PROS:
Easy syntax
Way too lightweight than MySQL
Way too faster I believe?
CONS:
Limited tools
No error handler
JSON ain’t a Programming Language or a database engine it’s just a file type where you can easily store some data in it.
You can’t really compress the JSON file cuz of data corruptions but MySQL does that already.
Conclusion:
If I really would like to use JSON to store data I would go for MongoDB or mongoose
You could use BSON to decrease file size.
I have no experience with BSON, but I know MongoDB uses it, and I used MongoDB for a while, so I assume when a popular database software uses it, it would be good, right?
Assuming they ran at the same time
Flow:
Script A reads X’s money = $100
Script B reads X’s money = $100
Script A does this: X[money] = $100+ 50(example) = $150 and saves to JSON
Script B does this: X[money] = $100 + 20(example) = $120 and saves to JSON
This won’t work. There are many scenarios just like this that are caused because your script isn’t really queueing requests.
It’s a decent attempt but you should just go the established route. There’s a reason why DB’s exist.
Json database will not be possible, with the amount of data your trying to write and read non stop its going to constantly error out and get the wrong data. Json isnt ment to be written and read from constantly non stop. (Ask qb-core before they changed management from json it would cause problems non stop and that was 2 json files for 1 resource.)
The only way it would slightly be possible is by having 1 json file per character and/or resource and that way you would be left with like 200+ files.
Check out any big discord bots for an example they use sql because json cant keep up with the requests needed by alot of clients at the same time.