Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format JSON with Unity

When I use JsonUtility.ToJson() from Unity (2019.3.0) it returns the JSON string in one line like:

{"ID":0,"Name":"David","HairColor":{"r":0,"g":0,"b":0}}

My question is: How can I make it to get:

{
    "ID":0,
    "Name":"David",
    "HairColor":{
        "r":0,
        "g":0,
        "b":0
    }
}

And can I use too JsonUtility.FromJson() to get the information as simple as always?

like image 423
SinfonierDominante Avatar asked Aug 11 '26 21:08

SinfonierDominante


1 Answers

You have to read the documentation:

JsonUtility.ToJson

public static string ToJson(object obj, bool prettyPrint);

prettyPrint If true, format the output for readability. If false, format the output for minimum size. Default is false.

like image 119
bolov Avatar answered Aug 13 '26 12:08

bolov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!