What is the best way to store data in a JSON?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jujumumu

Right now for all the data I store in JSON I do it all in one dictionary. So I can just do parse_json(save_file.get_as_text()). But it is also possible to save the data in the JSON in multiple lines. You would just have to iterate through each line to get each dictionary. Which is the best method?

:bust_in_silhouette: Reply From: Ram

What I do for my save game is create one dictionary of dictionary if you know what I mean.

Say I have a logic structure like so:


In my game script I iterate over all of the childrend and call their own save() functions that return a dictionary of values I want to save. Then I make a dictionary such as:

{"Calendar": calendar_dict, "Inventory": inventory_dict, "Weather": weather_dict}

That is easy to save and load on one line. If you want to make it on multiple lines on the save file you can use the JSON Beautifier addon but it is just for ease of reading the save file outside of the editor.

But which ones more efficient, or are they the same?

jujumumu | 2020-03-08 00:40

I have no idea about that. I really don’t care either at this stage. It takes a fraction of a second and until I would have a huge project that kind of performance discussion is often pointless.

Ram | 2020-03-08 10:28