JSON decoder/encoder eats arrays | General | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
JSON decoder/encoder eats arrays
No permission to create posts
October 10, 2018
11:44 pm
Avatar
heh

Gold
Members
Forum Posts: 30
Member Since:
June 30, 2017
sp_UserOfflineSmall Offline

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.

October 11, 2018
2:18 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 510
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

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

November 16, 2018
9:16 am
Avatar
heh

Gold
Members
Forum Posts: 30
Member Since:
June 30, 2017
sp_UserOfflineSmall Offline

Anyone who has Matlab license!

Please, report the issue to Matlab developers.
It is a minor issue to me, but must be a shame to them.

P.S. all this looks to me as if Matlab and ThingSpeak teams live on different planets 🙁

Forum Timezone: America/New_York

Most Users Ever Online: 114

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:

Beverlytreta, MartaKah, genevievecu69, henriettapj1, scottok3, kqjkze

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457