RaelB 4 Posted July 26, 2020 I'm using the latest version of superobject from here https://github.com/hgourvest/superobject. It fails to parse attached json file (return nil object). I have no problem using x-superobject, and notepad++ has no problem parsing it. Sample code: var O: ISuperObject; S: string; StrList: TStringList; begin StrList := TStringList.Create; try StrList.LoadFromFile(....'sample.json'); S := StrList.Text; O := SO(S); if O = nil then Memo1.Lines.Text := 'O = nil' else Memo1.Text := O.AsJSon(True); finally StrList.Free; end; Can anyone tell me why it fails? Is there a more recent version of superobject to use? hgourvest repo is no longer maintained. (My project is using superobject, so I don't want to swap to another library..) Thanks sample.json Share this post Link to post
Guest Posted July 26, 2020 This question interested me, and i am not familiar with superobject, so downloaded it and tried to figure out what is going on. the reason is so simple, if you debugged to see the reason to fail with a break point on this line class function TSuperObject.ParseEx(tok: TSuperTokenizer; str: PSOChar; len: integer; strict: Boolean; const this: ISuperObject; options: TSuperFindOptions; const put: ISuperObject; dt: TSuperType): ISuperObject; .. out: if(tok.err in [teSuccess]) then // here break point and the tok.err has teDepth begin .... The depth is defined as constant Quote SUPER_TOKENER_MAX_DEPTH = 32; Changing that value to 64 will solve your problem, keep in mind it will solve it for that file as the depth is not reaching 64. Share this post Link to post
Angus Robertson 574 Posted July 27, 2020 Did you see any downside to increasing SUPER_TOKENER_MAX_DEPTH. does it require more memory for every parse or something? Really need a way for tok.err to be exposed on failure, it's frustrating when superobject just fails for no obvious reason, although usually badly formatted json. Angus Share this post Link to post
Guest Posted July 27, 2020 2 hours ago, Angus Robertson said: Did you see any downside to increasing SUPER_TOKENER_MAX_DEPTH. does it require more memory for every parse or something? Saw no difference at all between 64, 128 and 256, done on the same file. 2 hours ago, Angus Robertson said: Really need a way for tok.err to be exposed on failure, it's frustrating when superobject just fails for no obvious reason, although usually badly formatted json. I agree, this might help, and well, i hate to suggest raising exception (i hate them all) but this case might be eligible to raise one, or you can add an extra parameter with tok.err result, may be safer overloaded version of those functions. Share this post Link to post
Angus Robertson 574 Posted July 27, 2020 Thanks, I shall update the superobject included with ICS appropriately. I did try the Json file on two web site parsers yesterday, one worked, one failed with an error but did not mention object depth, ran out of time to look further. Angus Share this post Link to post
Angus Robertson 574 Posted July 27, 2020 The ICS version of superobject now reports 'Error teDepth at line 1 column 6067 at depth 31' for the Json block, little more useful than nil result. The information is all there internally, just not reported. Not in SVN yet. Angus Share this post Link to post