Jump to content
RaelB

superobject fails to parse this json string

Recommended Posts

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

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

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
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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×