Wednesday 14 February 2018

JSON Find / Rewind

- or using the TJSONIterator without wearing a Cardigan.


Working with JSON files has been made easier over the years with Delphi - which btw turns 23 today - by either third-party libraries or especially within the RTL.

The System.JSON and the REST.JSON units have added the one-lines ObjectToJSON and JSONToObject, which can add a tiny bit of fat to the JSON generated to enable to get it back into your TObjectLists - but makes your code cleaner to read.

Another way is the adding of the TJSONWriter and TJSONReader which by using the TTextWriter and TTextReader mimics the .Net equivalents.

The TJSONWriter includes easy formatting of the output and in the System.JSON.Builders unit there are a couple of extra goodies, two of these being the TJSONObjectBuilder and the TJSONIterator.

I will dig a bit into TJSONIterator, since only its Recurse, Next and Return methods is mentioned on its DocWiki page here.