My JSON files keeps breaking when writing for some reason

You want to make sure that while the file is being read, it is not at the same time being written to, if so its likely to read empty. And not being written to while at the same time being written to by another change. And not being written to after being written to but since the corresponding read.

This is called locking, and is part of the process of writing your own database code. Instead, you could use a database package where it has all been done for you.

2 Likes