JSON parser using Variants

Hi Delphi experts.

I have a standalone unit for parsing JSON strings which depends on Variants. It worked great through Delphi 10.3 and fails in certain ways in Delphi 10.4 and 11.1. It enables parsing of JSON strings “like Javascript does” in terms of being able to use very simple “dot” and [ ] syntax. It was written before the JSON Iterator existed.

It is documented here: https://webhub.com/dynhelp:alias::varjsoncreate Please read that if you are wondering what it would it could possibly mean to “use javascript dot syntax” to access JSON objects. It is unusual.

I do not know how to find the person who wrote this for me originally. He was a subcontractor to a firm in Russia.

The problems are limited. They show up only when going deep into arrays within the json. “Obviously” the code is doing something wrong in terms of how and when it is releasing memory.

I am wondering whether anyone here would be willing and able to help me solve this. The unit is not currently in open source but it could be.

This approach to parsing JSON is not meant to be the fastest. It definitely is not. It is meant to be the most easy to read, and having just converted a project that was blowing up due to these bugs from this Variant approach over to the core Delphi JSON Iterator approach, I will say, I really think it is much easier to read. However that is obviously useless with bad memory management.

Before you volunteer, I should say that I tried chasing these bugs for a couple of days and it led to the Delphi IDE crashing. A lot. I had to reboot windows sometimes. Memory is being trampled and until that stops, development needs to be in a nice safe sandbox.

I have a DUnitX test unit which currently passes all tests, even in Delphi 11, because it does not yet include an example that drills down into tested arrays the way that my project sample did. I will be sort that part out. Obviously there needs to be a straightforward reproducible issue.

Well… if I have not already scared you away and you know Variants, I would very much like to hear from you. Happy to send you a copy of the unit, probably not attached here but rather by email.


I’ll just mention this in passing … was mentioned on fb … a small unit to do read-only json in the manner you are mentioning. Probably hasn’t had extensive testing yet …

1 Like

Thanks Paul. That is similar in intent.

The author of the TulipEasyJsonReader is open to collaboration, and I sent him my code. Hopefully the end result will be quite worthwhile. Thanks again for the referral.

1 Like

Another possibly relevant link …