How to save JSON file properly formatted?

Hello,
I’m saving a JSON file to disk.
This JSON should be easily editable by external editor.
The problem is that saving from Unity with “WriteAllText” it create a file that is not properly formatted as you would expect.
It’s all in a single line, and can become quite hard to read and to modify by humans!

Is there a smarter way (or a better Method) to save the JSON, so to have a “nice”, easily readable and easily editable file?
Or, maybe, do I have to write my own function to split each object, with its value in lines, etc… (it would be a mess :hushed:)?

Many thanks!

what do you mean by this? what have you tried so far?
if you mean JsonUtility.ToJson() its 2nd argument is called prettyPrint for a reason

edit:
did you mean System.IO.File.WriteAllText? but then what did you use to build a JSON to begin with?

3 Likes

Damn… so in a hurry that I didn’t even look at the arguments of ToJson
Really appreciated!
Many many thanks

1 Like

you’re welcome

1 Like