For your json you can use just one line of the code
- Using new JsonNode
string formattedJson = System.Text.Json.Nodes.JsonNode.Parse(json).ToString();
- Using traditional JsonDocument
string formattedJson = System.Text.Json.JsonSerializer
.Serialize( JsonDocument.Parse(json),
new JsonSerializerOptions() { WriteIndented = true });
In both cases result is the same
{
"Sound": true,
"Volume": 80,
"Indexing": true,
"Settings": [
{
"Item1": {
"Key": 1,
"Value": 1
},
"Item2": 1,
"Item3": 0,
"Item4": 1,
"Item5": 0,
"Item6": -1,
"Item7": false
},
{
"Item1": {
"Key": 1,
"Value": 2
},
"Item2": 2,
"Item3": 0,
"Item4": 1,
"Item5": 1,
"Item6": 2,
"Item7": true
},
{
"Item1": {
"Key": 3,
"Value": 2
},
"Item2": 1,
"Item3": 0,
"Item4": 2,
"Item5": 2,
"Item6": 3,
"Item7": false
},
{
"Item1": {
"Key": 3,
"Value": 3
},
"Item2": 1,
"Item3": 0,
"Item4": 1,
"Item5": 0,
"Item6": 4,
"Item7": false
}
]
}