Re: [fpc-pascal] Formating JSON outputs

2014-01-28 Thread Sven Barth

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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Formating JSON outputs

2014-01-28 Thread Michael Van Canneyt



On Tue, 28 Jan 2014, luciano de souza wrote:


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]


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?


Yes. Use the FormatJSON function.
Note that it is slower than the AsJSON function, because of the formatting.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal