|
53 | 53 | % SingletCell [1|0]: if 1, always enclose a cell with "[]" |
54 | 54 | % even it has only one element; if 0, brackets |
55 | 55 | % are ignored when a cell has only 1 element. |
| 56 | +% EmptyArrayAsNull [0|1]: if set to 1, convert an empty array to |
| 57 | +% JSON null object; empty cells remain mapped to [] |
56 | 58 | % ForceRootName [0|1]: when set to 1 and rootname is empty, savejson |
57 | 59 | % will use the name of the passed obj variable as the |
58 | 60 | % root object name; if obj is an expression and |
|
157 | 159 | opt.arraytostruct = jsonopt('ArrayToStruct', 0, opt); |
158 | 160 | opt.parselogical = jsonopt('ParseLogical', 0, opt); |
159 | 161 | opt.arrayindent = jsonopt('ArrayIndent', 1, opt); |
| 162 | +opt.emptyarrayasnull = jsonopt('EmptyArrayAsNull', 0, opt); |
160 | 163 | opt.inf = jsonopt('Inf', '"$1_Inf_"', opt); |
161 | 164 | opt.nan = jsonopt('NaN', '"_NaN_"', opt); |
162 | 165 | opt.num2cell_ = 0; |
|
313 | 316 | if (~iscell(item) && ~isa(item, 'string')) |
314 | 317 | error('input is not a cell or string array'); |
315 | 318 | end |
316 | | -if (isa(item, 'string')) |
317 | | - level = level - 1; |
318 | | -end |
319 | 319 | isnum2cell = varargin{1}.num2cell_; |
| 320 | + |
320 | 321 | if (isnum2cell) |
321 | 322 | item = squeeze(item); |
322 | 323 | if (~isvector(item)) |
|
325 | 326 | end |
326 | 327 |
|
327 | 328 | dim = size(item); |
328 | | -% if(ndims(squeeze(item))>2) % for 3D or higher dimensions, flatten to 2D for now |
329 | | -% item=reshape(item,dim(1),numel(item)/dim(1)); |
330 | | -% dim=size(item); |
331 | | -% end |
332 | 329 | len = numel(item); |
333 | 330 | ws = varargin{1}.whitespaces_; |
334 | 331 | padding0 = repmat(ws.tab, 1, level); |
|
741 | 738 | end |
742 | 739 |
|
743 | 740 | if (isempty(mat)) |
744 | | - txt = '[]'; |
| 741 | + if(varargin{1}.emptyarrayasnull) |
| 742 | + txt='null'; |
| 743 | + else |
| 744 | + txt = '[]'; |
| 745 | + end |
745 | 746 | return |
746 | 747 | end |
747 | 748 | if (isinteger(mat)) |
|
0 commit comments