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)

    Like


  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” ๐Ÿ™‚

    Like


  3. Gustav Schubert I don’t unescape those, but that could be an improvement.


    Edit: it would be pretty straightforward, actually, but I prefer to see exactly what we send to the client.

    Like


  4. 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.

    Like


  5. 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

    Like


  6. 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.

    Like

Leave a Reply to Gustav Schubert Cancel reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.