### Pretty String Object and Array

Example of converting a JSON string, being an Object or Array to a Pretty String.
Requires the JSON Library.
Object (Map)
'Converts a json string holding an object to a json pretty string.
'Makes use of the Json Library.
'Example:
'{"Field1":"Content1", "Field2":"Content2", "Field3":{"Content":"Content3"}}
'converted to
'{
' "Field2": "Content2",
' "Field3": {
' "Content": "Content3"
' },
' "Field1": "Content1"
'}
`Sub JsonMapToPrettyString(in As String, indent As Int) As String
Dim parser As JSONParser
parser.Initialize(in)
Dim root As Map = parser.NextObject
' Convert the json in string as a json pretty string
Dim jsongen As JSONGenerator
jsongen.Initialize(root)
Return jsongen.ToPrettyString(indent)
End Sub`
Array (List of Maps)
'Converts a json string holding an array to a json pretty string.
'Makes use of the Json Library.
'Example:
'[
'{"Field1":"Content1", "Field2":"Content2", "Field3":{"Content":"Content3"}},
'
'{"Field11":"Content11", "Field22":"Content22", "Field33":{"Content":"Content33"}}
']
'converted to
'[
' {
' "Field2": "Content2",
' "Field3": {
' "Content": "Content3"
' },
' "Field1": "Content1"
' },
' {
' "Field11": "Content11",
' "Field22": "Content22",
' "Field33": {
' "Content": "Content33"
' }
' }
']
`Sub JsonListToPrettyString(in As String, indent As Int) As String
Dim parser As JSONParser
parser.Initialize(in)
Dim root As List = parser.NextArray
' Convert the json in string as a json pretty string
Dim jsongen As JSONGenerator
jsongen.Initialize2(root)
Return jsongen.ToPrettyString(indent)
End Sub`

Changed: , Category: JSON, File: T6C210M1539.htm, ID: 1539