I wrote a function to make JSON more readable, and naturally I wonder if I missed something crucial so that it…

I wrote a function to make JSON more readable, and naturally I wonder if I missed something crucial so that it eventually will break?

There are probably more efficient ways to work with strings than concatenating character by character, but performance was not a key goal.

I hereby commit it to public code review 😉

https://pastebin.com/Juks92Y2

10 thoughts on “I wrote a function to make JSON more readable, and naturally I wonder if I missed something crucial so that it…


  1. I have tested PrettyFormat as a replacement for this:


    function JsonInfo.FormatJSON(const s: string): string;


    var


    tmp: TJsonValue;


    begin


    tmp := TJSONObject.ParseJSONValue(s);


    Result := TJson.Format(tmp);


    tmp.Free;


    end;


    PrettyFormat looks better!


    (The array brackets are now properly aligned.)


    “But”, the international characters are ‘presented’ differently.


    “Lu00F3pez” // <– yours (PrettyPrint)


    “LĂłpez” // <– theirs (TJson.Format)


  2. all there in XSuperObject. By the way the JSON plugin for NotePad++ is pretty good too. But as they say “telling a programmer there is already a library for that is like telling a songwriter there is already a few songs about love” 🙂


  3. Russell Weetch We don’t use XSuperObject. This was written to make the JsonRPC requests / responses reasonably readable in the log viewer. It is pretty dumb, as it has no perception of hierarchy and treats objects and arrays the same way.


  4. Lars Fosdal I mostly use it for building JQuery structures as it had the Raw property which is needed. I do like the interface approach ( based on Superobject). It would be good to have a standard interface that implementations could fulfil


  5. Russell Weetch I use RTTI and Rest.Json.


    aJsonString := TJson.ObjectToJsonString(MyObject,


    [joIgnoreEmptyStrings, joIgnoreEmptyArrays, joDateIsUTC, joDateFormatISO8601]);


    MyObject := TJson.JsonToObject(aJsonString);


    I am told that it is slow, but it seems fast enough for our purposes.