[fpc-pascal] Formating JSON outputs

Sven Barth pascaldragon at googlemail.com
Tue Jan 28 13:15:53 CET 2014


Am 28.01.2014 12:29, schrieb luciano de souza:
> Hello all,
>
> JSON is a very easy format to handle with Freepascal. However, the
> output is not so readable when the number of registers increase. An
> example of it is:
[snip]
> s.text := r.AsJson;
> s.SavetoFile('test.txt');
[snip]
> The corresponding output is:
>
> { "people" : [{ "name" : "Luciano de Souza", "age" : 38, "city" :
> "NiterĂ³i", "country" : "Brazil" }, { "name" : "Mariella Molinari",
> "age" : 29, "city" : "Padova", "country" : "Italy" }] }
>
> My question is: is there a way to automatically format it? Breaking
> lines? Becoming easy the reading?
TJSONData.AsJSON basically uses the format options "foSingleLineArray, 
foSingleLineObject" (it's not implemented that way though, put it 
appears like this ^^). To manually influence this you should take a look 
at TJSONData.FormatJSON.

Regards,
Sven



More information about the fpc-pascal mailing list