![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Pretty Print JSON (Formatter, Beautifier)Demonstrates how to emit JSON in a pretty, human-readable format with indenting of nested arrays and objects.
IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf jsonStr.s = "{" + 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.i = CkJsonObject::ckLoad(json,jsonStr) If success <> 1 Debug CkJsonObject::ckLastErrorText(json) CkJsonObject::ckDispose(json) ProcedureReturn EndIf ; To pretty-print, set the EmitCompact property equal to 0 CkJsonObject::setCkEmitCompact(json, 0) ; If bare-LF line endings are desired, turn off EmitCrLf ; Otherwise CRLF line endings are emitted. CkJsonObject::setCkEmitCrLf(json, 0) ; Emit the formatted JSON: Debug CkJsonObject::ckEmit(json) CkJsonObject::ckDispose(json) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.