You can also use the following methods of our Open Source SynCommons.pas :
var json,new: RawUTF8; begin json := '{"menu": {"header": "JSON viewer", "items": [{"id": "Delphi"},{"id": "Pascal", "label": "Nice tree format"}, null]}}'; new := JSONReformat(json,jsonHumanReadable); ...
Here new will contain:
{ "menu": { "header": "JSON viewer", "items": [ { "id": "Delphi" }, { "id": "Pascal", "label": "Nice tree format" }, null ] } }
If you are using jsonUnquotedPropName format:
new := JSONReformat(json,jsonUnquotedPropName);
You will get the following extended syntax (similar to the one used in JavaScript or the MongoDB shell):
{ menu: { header: "JSON viewer", items: [ { id: "Delphi" }, { id: "Pascal", label: "Nice tree format" }, null ] } }
This syntax is accepted as valid input for all JSON functions in our Open Source framework, as an alternative to the default JSON syntax. We found this quite useful, for example. for configuration files.
Please note that our JSONReformat() function is very fast. It converts a massive 190 MB of non-convertible JSON content from CityLots to 400 MB decorated with JSON (intended and with margins) in 1.4 seconds. SuperObject is simply capable of reading it in 10 seconds and uses 1.1 GB only to store 190 MB of content. And DBXJSON cannot even load data: it consumes all 32-bit memory - under Win64 (XE6), takes 50 seconds and uses 3 GB of RAM to read 190 MB JSON. See this article for some numbers .
source share