Stop 'jsonencode' squashing cell arrays?
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 JSON Format에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!