Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 10, 2015

Conversation

insikk
Copy link
Contributor

@insikk 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 added a commit that referenced this pull request Nov 10, 2015
thanks, the proposed changes are now merged in jsonlab.
@fangq fangq merged commit 69404cb into NeuroJSON:master Nov 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants