Stop 'jsonencode' squashing cell arrays?
Ältere Kommentare anzeigen
Hi,
I've noticed a behaviour of 'jsonencode' (that I don't want), which is to squash cell arrays of doubles into multidimensional arrays when it can. To see this, I made the following example:
clc
% Make up our dummy struct, containing cell arrays of equal size....
myDat.simulation = {rand(10,2) ; rand(10,2)};
myDat.data = {rand(10,3) ; rand(10,3)};
jMyDat = jsondecode(jsonencode(myDat));
myDat
jMyDat
% Make up our dummy struct, containing cell arrays of different size....
myDat2.simulation = {rand(13,2) ; rand(10,2)};
myDat2.data = {rand(13,3) ; rand(10,3)};
jMyDat2 = jsondecode(jsonencode(myDat2));
myDat2
jMyDat2
..in other words, 'jsonencode' collapses the cell arrays into a single 3D array is the arrays are the same size, but won't if they are different.
The trouble is that I need to preserve the cell arrays for downstream stuff, so the second behaviour(i.e. not collapsing the cells) is the one I want.
Is there a way to force jsonencode to preserve the cell arrays is all cases?
Cheers,
Arwel
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu JSON Format finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!