JSON decoder/encoder eats arrays | General | Forum

The ThingSpeak community site has been upgraded to a new site. This site is currently in read-only mode. You can ask questions or post and read discussions on the new site.

Please consider registering

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

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


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 =


In the following example, codec eats the internal array in JSON structure:

json_inst = jsondecode ('{"array":[{"a":"b"}]}');
jsonencode (json_inst)

ans =


The second case must be a bug, because the result makes no sense.

October 11, 2018
2:18 pm

Forum Posts: 885
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.

If you own a MATLAB license, you could contact support for help with this issue, depending on the terms of your license.


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

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: 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, winzy99

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457