11:44 pm


Gold
June 30, 2017

Hello
On certain strings jsondecode / jsonencode in Matlab Analysis eat arrays.
First example reproduces the original string correctly:
json_inst = jsondecode ('{"array":[{"a":"b"},{"c":"d"}]}');
jsonencode (json_inst)
ans =
'{"array":[{"a":"b"},{"c":"d"}]}'
In the following example, codec eats the internal array in JSON structure:
json_inst = jsondecode ('{"array":[{"a":"b"}]}');
jsonencode (json_inst)
ans =
'{"array":{"a":"b"}}'
The second case must be a bug, because the result makes no sense.
2:18 pm


Moderators
March 7, 2017

jsonencode is definitely a MATLAB issue. I would have a look at MATLAB answers, or the doc for jsonencode.
https://www.mathworks.com/matlabcentral/answers/index
https://www.mathworks.com/help/matlab/ref/jsonencode.html
If you own a MATLAB license, you could contact support for help with this issue, depending on the terms of your license.
*Update*
This is an expected behavior from jsonencode.
In MATLAB arrays with one dimension are converted to scalar. The function jsonencode is considered an informal interface, and thus round trips are not guaranteed.
One possible workaround: If you know that something should be a scalar array, it should be wrapped in a cell array of length one. For example, j.signatures.arguments{1}.widgetData.choices = {j.signatures.arguments{1}.widgetData.choices};
Most Users Ever Online: 166
Currently Online:
25 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
huldacormier, bogart, estebanmateo93, mikewrite, onlinebusiness, winzy99Moderators: cstapels: 460
Administrators: Hans: 405, lee: 457