Features

It will store any string property into UTF-8 (whatever the string type was in the class definition), handle integer or currency or floating point values, sets and enumerates as integer, and will store TDateTime as Iso8601 standard text.

It will also handle TCollection and TStrings properties, writing them as JSON arrays of respectively JSON objects or JSON strings.


From Objects to JSON

For instance, the following code will create some objects in memory:

Coll := TCollTst.Create;
Coll.One.Name := 'test"\2';
Coll.One.Color := 1;
Coll.Coll.Add.Color := 10;
Coll.Coll.Add.Name := 'name';
JSONContent := ObjectToJSON(Coll);

The resulting JSON content is UTF-8 encoded, and can be formated in an human-readable layout:

{
 "One":
 {
  "Color": 1,
  "Length": 0,
  "Name": "test\"\2"
 },
 "Coll":
 [
  {
   "Color": 10,
   "Length": 0,
   "Name": ""
  },
  {
   "Color": 0,
   "Length": 0,
   "Name": "name"
  }
 ]
}

The default normal layout is more compact, and store exactly the same data:

{"One":{"Color":1,"Length":0,"Name":"test\"\2"},"Coll":[{"Color":10,"Length":0,"Name":""},{"Color":0,"Length":0,"Name":"name"}]}


From JSON to objects

Of course, you can reverse the conversion, and populate your Delphi class instance from JSON encoded data with just one line of code:

SyntaxErrorPointer := JSONToObject(TObject(Coll),@JSONContent[1],ErrorFlag);

In case of parsing error, ErrorFlag will be true, and SyntaxErrorPointer will point to the faulty part of the JSON content.


Speed

The JSON processing is very fast. Code is deeply optimized, and has no limitation but available memory.

In fact, the JSON parser unserialize the JSON in-place. Avoiding allocation of small memory blocks for each item make it much faster than any other mechanism.

Even the properties access via RTTI was using some optimized asm functions of the framework, faster than default Delphi RTTI, and with no speed comparison with the so called "new RTTI" functions, available in latest version of Delphi.

Feedback and comments are welcome on our forum.