Anybody used this JSON library? How about the stability? It allows accessing json properties using the dotted notion, it's very similar to using literal object in JavaScript, as shown bellow, it's a very convenient and concise syntax, IMHO, thus attractive to me and want to use it.

Anybody used this JSON library? How about the stability?  It allows accessing json properties using the dotted notion, it's very similar to using literal object in JavaScript, as shown bellow, it's a very convenient and concise syntax, IMHO, thus attractive to me and want to use it.

procedure DoFromScratch;
var
  j, a : TJSONObject;
begin
  // Create a new empty JSON object.
  j := NewJSONObject;

  // Start assigning properties.  Properties that don't already exist are
  // automatically added when assigned.
  j.x := 50;
  j.text := 'This is my message';

  // Arrays must be assigned using Variant Arrays
  j.buttons := VarArrayOf(['Ok','Cancel']);

  // Object properties can be automatically created by simply accessing it
  // and assigning required properties
  j.User.FirstName := 'Fred';
  j.User.LastName := 'Willard';

  // The JSON object can be converted to a JSON string with the AsJSON method.
  WriteLn(j.AsJSON);
end;
https://code.google.com/p/delphijson/

Comments

  1. It uses the variant's dynamic name resolution, so while the syntax is simple and close to JSON, be aware that you'll pay for it in terms of performance at runtime by having to go through the Variant's name resolution code (also everything being resolved at runtime it's possible to write code that will compile but crash in horrible ways).

    Another side aspect if you're going to use it to access 3rd-party JSON (rather than specify your JSON structure) is that there are some JSON fields you won't be able to access, as you'll be limited to valid Delphi identifiers, so JSON field names with "$" in them or with other characters won't be accessible (cf. http://stackoverflow.com/questions/8676011/illegal-characters-in-object-or-json-key).

    ReplyDelete

  2. Eric Grange Thanks for the notes! In my use case I don't especially care about the performance since it'll handles small collection of data. But your second note made me think I'd better of using the good old SuperObject!

    ReplyDelete

Post a Comment