Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonlab_selftest crashes in MATLAB 2017a but not 2016b #37

Closed
ghost opened this issue May 22, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@ghost
Copy link

commented May 22, 2017

Trying to run jsonlab_selftest.m in MATLAB 2017a crashes with the following error stack:

>> jsonlab_selftest
===============================================
>> example1.json
{
	"data": {
		"firstName": "John",
		"lastName": "Smith",
		"age": 25,
		"address": {
			"streetAddress": "21 2nd Street",
			"city": "New York",
			"state": "NY",
			"postalCode": "10021"
		},
		"phoneNumber": [
			{
				"type": "home",
				"number": "212 555-1234"
			},
			{
				"type": "fax",
				"number": "646 555-4567"
			}
		]
	}
}

{"data": {"firstName": "John","lastName": "Smith","age": 25,"address": {"streetAddress": "21 2nd Street","city": "New York","state": "NY","postalCode": "10021"},"phoneNumber": [{"type": "home","number": "212 555-1234"},{"type": "fax","number": "646 555-4567"}]}}

===============================================
>> example2.json
Undefined function or variable 'st'.

Error in savejson>matlabobject2json (line 448)
txt=struct2json(name,st,level,varargin{:});

Error in savejson>obj2json (line 175)
    txt=matlabobject2json(name,item,level,varargin{:});

Error in savejson>cell2json (line 216)
       txt{end+1}=obj2json(name,item{i,j},level+(dim(1)>1)+(len>bracketlevel),varargin{:});

Error in savejson>obj2json (line 169)
    txt=cell2json(name,item,level,varargin{:});

Error in savejson>struct2json (line 285)
	    txt{end+1}=obj2json(names{e},item(i,j).(names{e}),...

Error in savejson>obj2json (line 171)
    txt=struct2json(name,item,level,varargin{:});

Error in savejson>struct2json (line 285)
	    txt{end+1}=obj2json(names{e},item(i,j).(names{e}),...

Error in savejson>obj2json (line 171)
    txt=struct2json(name,item,level,varargin{:});

Error in savejson>struct2json (line 285)
	    txt{end+1}=obj2json(names{e},item(i,j).(names{e}),...

Error in savejson>obj2json (line 171)
    txt=struct2json(name,item,level,varargin{:});

Error in savejson>struct2json (line 285)
	    txt{end+1}=obj2json(names{e},item(i,j).(names{e}),...

Error in savejson>obj2json (line 171)
    txt=struct2json(name,item,level,varargin{:});

Error in savejson>struct2json (line 285)
	    txt{end+1}=obj2json(names{e},item(i,j).(names{e}),...

Error in savejson>obj2json (line 171)
    txt=struct2json(name,item,level,varargin{:});

Error in savejson>struct2json (line 285)
	    txt{end+1}=obj2json(names{e},item(i,j).(names{e}),...

Error in savejson>obj2json (line 171)
    txt=struct2json(name,item,level,varargin{:});

Error in savejson (line 140)
json=obj2json(rootname,obj,rootlevel,opt);

Error in jsonlab_selftest (line 9)
    json=savejson('data',loadjson(fname));
 
448 txt=struct2json(name,st,level,varargin{:});

Output of MATLAB's "ver" command:

----------------------------------------------------------------------------------------------------
MATLAB Version: 9.2.0.538062 (R2017a)
MATLAB License Number: XXX
Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 15063)
Java Version: Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
----------------------------------------------------------------------------------------------------
MATLAB                                                Version 9.2         (R2017a)
Image Processing Toolbox                              Version 10.0        (R2017a)
Signal Processing Toolbox                             Version 7.4         (R2017a)
Statistics and Machine Learning Toolbox               Version 11.1        (R2017a)

On the same machine, running jsonlab_selftest with MATLAB 2016b works fine. Output of that "ver" command:

MATLAB Version: 9.1.0.441655 (R2016b)
MATLAB License Number: XXX
Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 15063)
Java Version: Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
----------------------------------------------------------------------------------------------------
MATLAB                                                Version 9.1         (R2016b)
Image Processing Toolbox                              Version 9.5         (R2016b)
Parallel Computing Toolbox                            Version 6.9         (R2016b)
Statistics and Machine Learning Toolbox               Version 11.0        (R2016b)
@cheristi

This comment has been minimized.

Copy link

commented May 24, 2017

Since Matlab 2017a value = ["GML", "XML"] produces a valid string array.
A simple bugfix is swapping l. 211 (object=eval(arraystr)) of loadjson.m with the following snippet:
```

tmpobj=eval(arraystr);  

assert(iscell(tmpobj)); %Since matlab 2017a ["GML", "XML"] produces a valid string array  

object = tmpobj;  
@fangq

This comment has been minimized.

Copy link
Owner

commented May 31, 2017

@felipeger, I also wasn't able to reproduce this error on my end. See my screen capture.
jsonlab_2017a_issue37

@fangq

This comment has been minimized.

Copy link
Owner

commented May 31, 2017

@cheristi, I tried the below command and it runs without a problem in matlab 2017a (Linux version).

dd=loadjson('["GML", "XML"]')

dd =

  1×2 cell array

    ["GML"]    ["XML"]

this output is the same as old matlab releases. I am closing this issue, but if the problem persists, please reopen it.

@fangq fangq closed this May 31, 2017

@aLittleFishThu

This comment has been minimized.

Copy link

commented Oct 31, 2017

Hi,
I tried the simpledd=loadjson('["GML", "XML"]'), it is OK.
but I still encountered the same problem with example2.json in my Matlab 2017b.

@hillsm

This comment has been minimized.

Copy link

commented Nov 13, 2017

@fangq, perhaps you should try dd=loadjson(["GML","XML"]).

Starting from R2017a (on Windows at least) it is possible to make a string array like this: item="GML" . item is considered an object consisting of one element, but without properties. Hence, matlabobject2json fails.

@CitizenInsane

This comment has been minimized.

Copy link

commented Jul 5, 2018

Here is a better fix to force loadjson to return char type instead of string type after object=eval(arraystr); for backward compatibility ...

NB: It may be good to have an option to choose between the two types but for some cases like loadjson('["Titi", "Toto", null]') it will fall in the catch statement which return char type with or without below patch:

object=eval(arraystr);
if (~verLessThan('matlab', '9.1'))
           
    % Starting from R2016b, there is the new "string" data type, so
    % parsing object = eval('{"Titi", "Toto"}') will work but
    % return "string" array instead of "char" array.
    % So here replacing all "string" types with "char" type in the cell array
    if (iscell(object))
        logic = cellfun(@isstring, object);
        object(logic) = cellstr(object(logic));
    elseif (isstring(object))
        object = char(object);
    end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.