This has been confirmed as a bug by someone from Mathworks Tech support. I have attached a sample data set that exhibits this error, which can be loaded using:
a = fileread('json2.json');
and then decoded with the same decoder as used in webread using:
out = matlab.internal.webservices.fromJSON(a)
which will have the size mismatched arrays in out.results.series.values (cells 50, 84 and 85).
There is a fairly simple workaround, however. Specify the content type in weboptions, which will create the same 'a' as downloading the JSON manually and using fileread.
a = webread(URL, weboptions('ContentType','text'));
The null values can then be replaced by NaN using strrep and decoded:
a = strrep(a,'null','NaN');
out = matlab.internal.webservices.fromJSON(a);
This will give a correctly sized 88x18 double matrix (instead of 88 cells containing double matrices) in out.results.series.values with NaN at the right positions.
1 Comment
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/300985-handling-of-null-in-json-sourced-from-webread#comment_388157
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/300985-handling-of-null-in-json-sourced-from-webread#comment_388157
Sign in to comment.