Reading JSON Data: TJsonTextReader vs. TJsonObject

Reading JSON Data: TJsonTextReader vs. TJsonObject
Following my previous post about using JSON as a file format I've been experimenting with a test application. It seems there are two ways to parse a JSON file using Delphi: the first uses the "old" TJsonObject method which loads everything into memory, and the second uses TJsonTextReader method reading everything in sequentially. The latter seems to be preferred my most due to the speed and small memory footprint. However, my aim is to create a file system that is forward compatible i.e. when implemented, old versions of my application will be able to read file created by newer versions. To accomplish this the application must be able to skip over any property that it doesn't recognize. Am I correct in thinking this isn't easy to do using the TJsonTextReader method? Is the "old" TJsonObject method preferred for being able to skip over properties? Am I missing anything? Anyone know of any good examples of this behavior?

- Steve

Comments

  1. I prefer an other way to deal with JSON; with my unit you can serialize/unseriale anything to/from JSON

    it work very well with records and dynamic array, with classes it's a bit more complex, because you can't just reset an object with a Finalize() and FillChar(0) or you have to deal with constructors that can lead to complex situations.

    For objects, I usully implement a clear method that I call before loading the JSON informations, but most of the time I put everything in a Record (see RSP-20848).

    github.com - LetsEncryptDelphi

    ReplyDelete
  2. It should be easy. Look at TJsonReader.Skip method.

    ReplyDelete

Post a Comment