Resolving bug that cell type is converted to json with transposed data #12

Merged
merged 1 commit into from Nov 10, 2015

Projects

None yet

2 participants

@insikk
Contributor
insikk commented Oct 26, 2015

Problem

Saving 2D cell array resulted in transposed data in json string.

Here is example. We save 2 by 3 cell array. Saving it to JSON, then loading the saved JSON string gives 3 by 2 array, which is unintended transposed data.

mixed_cell = { 1, 2, 3;...
              4, 5, 6}; 
size(mixed_cell)
% ans =
%      2     3

str = savejson(mixed_cell)
% str =
% {
%   "mixed_cell": [
%       [
%           1,
%           4
%       ],
%       [
%           2,
%           5
%       ],
%       [
%           3,
%           6
%       ]
%   ]
% }

obj = loadjson(str)
% obj = 
%   mixed_cell: [3x2 double]

Solution

I changed loop order in function cell2json in savejson.m file.

Result

mixed_cell = { 1, 2, 3;...
              4, 5, 6}; 
size(mixed_cell)
% ans =
%      2     3
str = savejson(mixed_cell)
% str =
% {
%   "mixed_cell": [
%       [
%           1,
%           2,
%           3
%       ],
%       [
%           4,
%           5,
%           6
%       ]
%   ]
% }

obj = loadjson(str)
% obj = 
%    mixed_cell: [2x3 double]
@fangq fangq merged commit 69404cb into fangq:master Nov 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment