While using the SuperObject
library, a single JSON object currently gets indented like so:
{
"name": "value",
"int_arr": [
1,2,3],
"obj_arr": [
{
"this": "that"
},{
"some": "thing"
}],
"another": 123
}
However, this indentation/formatting is not the same "user-friendly" or "human-readable" as JSON is all hyped up to be. I understand in computer language, this doesn't necessarily matter, but I'd like to format it like so instead:
{
"name": "value",
"int_arr": [1,2,3],
"obj_arr": [
{
"this": "that"
},
{
"some": "thing"
}
],
"another": 123
}
For example, when using JSONLint to validate/format JSON code, it does so in a much cleaner manner.
How can I go about modifying the SuperObject
library to format it differently? Is there a particular place in the library which defines these formatting rules? Or would I have to dig into the code in many different places to change this?
Thanks to the comment by
David A
, it was rather simple to implement these changes (after formatting the source and understanding how the library's code works). All the formatting is implemented inTSuperObject.Write
, and all of such changes can be made here.There was only one issue I could not figure out, which was arrays of types other than objects - the values will go to the next line. But at least array endings and arrays of objects have line breaks and indentation as desired.
Here's the modified version of
TSuperObject.Write
below (most subroutines not included to save space). Changes commented:Constant:
Subroutine:
Procedure body:
That code would produce JSON data like so: