#1 2016-01-19 20:26:48

avista
Member
Registered: 2014-01-06
Posts: 63

JSON Parser Bug

In TJSONCustomParserRTTI.ReadOneLevel():

(Using the nightly build dated 2016-01-16)

    ptCustom:
      P := TJSONCustomParserCustom(Prop).CustomReader(P,Data^,EndOfObject);

Needs to be:

    ptCustom: begin
      P := TJSONCustomParserCustom(Prop).CustomReader(P,Data^,EndOfObject);
      if P=nil then
       exit;
    end;

Otherwise the parsing continues and data corruption can occur.

I'm using this with RecordLoadJSON() and the problem happened in a nested record, when an integer was expected, but a string value was specified.

Currently, RecordLoadJSON() returns nil if the JSON was not valid, but it would be incredibly helpful if there was a way to validate the JSON against the record/object it's being de-serialzed to, so that I can see exactly where the parsing failed, instead of having to hunt through some large JSON strings (especially with nested objects and arrays) to find the offending syntax or type mismatch. It's like hunting for a needle in a haystack. smile

Even having a separate function to perform this kind of validation would be extremely useful!

Last edited by avista (2016-01-19 20:29:51)

Offline

#2 2016-01-20 12:32:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: JSON Parser Bug

Should be fixed by http://synopse.info/fossil/info/bab3b6f191

I've also ensured TJSONCustomParserRTTI.ReadOneLevel would let P point on the faulty text on parse error. This should be the first step to ease JSON validation.

Offline

Board footer

Powered by FluxBB