Save JSON with paragraphs

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

I program a little game, where the data is taken from json-files.
I can load, edit and save a json in the program like a in-built json-editor (scene with buttons and a textedit to view and edit the json).
The JSON-Files are big and i must use paragraphs to have an overview. In Wordpad/Notepad++ this is easy, but when after i save the json with the in-built-editor, the json is 1 line of code. I want to make paragraphs and when i save it, it should be there when i load.
How can i do that?

:bust_in_silhouette: Reply From: EquineRecline

It’s not possible. JSON is meant to be single line values. If you want line breaks, you’ll need to find a software that will automatically create them from the new line marker.

This question again passed my view and I just had an idea. I just thought of it and haven’t tried it yet, but what if you saved both a JSON and a txt file? The JSON could be a single line which you don’t touch, but the txt could include line breaks and be the one you modify. Then when loading it into Godot, you could just check which one is more recent and load that one. Or depending how many keys your JSON files have, you could save each one as a text file, then load them each back in individually, parsing the line breaks to “\n”, then setting them to the value of their respective key.

I’ll try this and report my results.

EquineRecline | 2022-08-08 17:00