B4X
B4X
Pretty Print JSON (Formatter, Beautifier)
See more JSON Examples
Demonstrates how to emit JSON in a pretty, human-readable format with indenting of nested arrays and objects.Chilkat B4X Downloads
Dim success As Boolean = False
Dim json As ChilkatJsonObject
json.Initialize
Dim jsonStr As String = "{" & Chr(34) & "name" & Chr(34) & ": " & Chr(34) & "donut" & Chr(34) & "," & Chr(34) & "image" & Chr(34) & ":{" & Chr(34) & "fname" & Chr(34) & ": " & Chr(34) & "donut.jpg" & Chr(34) & "," & Chr(34) & "w" & Chr(34) & ": 200," & Chr(34) & "h" & Chr(34) & ": 200}," & Chr(34) & "thumbnail" & Chr(34) & ":{" & Chr(34) & "fname" & Chr(34) & ": " & Chr(34) & "donutThumb.jpg" & Chr(34) & "," & Chr(34) & "w" & Chr(34) & ": 32," & Chr(34) & "h" & Chr(34) & ": 32}}"
success = json.Load(jsonStr)
If success <> True Then
Log(json.LastErrorText)
Return
End If
' To pretty-print, set the EmitCompact property equal to False
json.EmitCompact = False
' If bare-LF line endings are desired, turn off EmitCrLf
' Otherwise CRLF line endings are emitted.
json.EmitCrLf = False
' Emit the formatted JSON:
Log(json.Emit)