|
8 | 8 | % matlab data structure with optional memory-map (mmap) table
|
9 | 9 | %
|
10 | 10 | % authors:Qianqian Fang (q.fang <at> neu.edu)
|
11 |
| -% created on 2011/09/09, including previous works from |
| 11 | +% created on 2011/09/09, including previous works from |
12 | 12 | %
|
13 | 13 | % Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
|
14 | 14 | % created on 2009/11/02
|
|
81 | 81 | % dat: a cell array, where {...} blocks are converted into cell arrays,
|
82 | 82 | % and [...] are converted to arrays
|
83 | 83 | % mmap: (optional) a cell array as memory-mapping table in the form of
|
84 |
| -% {{jsonpath1,[start,length,<whitespace>]}, |
85 |
| -% {jsonpath2,[start,length,<whitespace>]}, ...} |
| 84 | +% {{jsonpath1,[start,length,<whitespace_pre>]}, |
| 85 | +% {jsonpath2,[start,length,<whitespace_pre>]}, ...} |
86 | 86 | % where jsonpath_i is a string in the JSONPath [1,2] format, and
|
87 | 87 | % "start" is an integer referring to the offset from the begining
|
88 | 88 | % of the stream, and "length" is the JSON object string length.
|
89 |
| -% An optional 3rd integer "whitespace" may appear to record the |
90 |
| -% preceding whitespace length in case expansion of the data |
| 89 | +% An optional 3rd integer "whitespace_pre" may appear to record |
| 90 | +% the preceding whitespace length in case expansion of the data |
91 | 91 | % record is needed when using the mmap.
|
92 | 92 | %
|
| 93 | +% The format of the mmap table retruned from this function |
| 94 | +% follows the JSON-Mmap Specification Draft 1 [3] defined by the |
| 95 | +% NeuroJSON project, see https://neurojson.org/jsonmmap/draft1/ |
| 96 | +% |
93 | 97 | % Memory-mapping table (mmap) is useful when fast reading/writing
|
94 | 98 | % specific data records inside a large JSON file without needing
|
95 | 99 | % to load/parse/overwrite the entire file.
|
|
101 | 105 | % In the mmap jsonpath key, a '$' denotes the root object, a '.'
|
102 | 106 | % denotes a child of the preceding element; '.key' points to the
|
103 | 107 | % value segment of the child named "key" of the preceding
|
104 |
| -% object; '.[i]' denotes the (i+1)th member of the preceding |
| 108 | +% object; '[i]' denotes the (i+1)th member of the preceding |
105 | 109 | % element, which must be an array. For example, a key
|
106 | 110 | %
|
107 |
| -% $.obj1.obj2.[0].obj3 |
| 111 | +% $.obj1.obj2[0].obj3 |
108 | 112 | %
|
109 | 113 | % defines the memory-map of the "value" section in the below
|
110 | 114 | % hierarchy:
|
|
134 | 138 | %
|
135 | 139 | % [1] https://goessner.net/articles/JsonPath/
|
136 | 140 | % [2] http://jsonpath.herokuapp.com/
|
| 141 | +% [3] https://neurojson.org/jsonmmap/draft1/ |
137 | 142 | %
|
138 | 143 | % examples:
|
139 | 144 | % dat=loadjson('{"obj":{"string":"value","array":[1,2,3]}}')
|
|
335 | 340 | pos=endpos;
|
336 | 341 | pos=parse_char(inputstr, pos, ']');
|
337 | 342 | if(pbar>0)
|
338 |
| - waitbar(pos/length(inStr),pbar,'loading ...'); |
| 343 | + waitbar(pos/length(inputstr),pbar,'loading ...'); |
339 | 344 | end
|
340 | 345 | return;
|
341 | 346 | end
|
|
363 | 368 | while 1
|
364 | 369 | varargin{1}.arraydepth_=arraydepth+1;
|
365 | 370 | if(nargout>3)
|
366 |
| - varargin{1}.jsonpath_=[origpath '.' sprintf('[%d]',length(object))]; |
| 371 | + varargin{1}.jsonpath_=[origpath sprintf('[%d]',length(object))]; |
367 | 372 | mmap{end+1}={varargin{1}.jsonpath_, [pos, 0, w2]};
|
368 | 373 | [val, pos, index_esc, newmmap] = parse_value(inputstr, pos, esc, index_esc,varargin{:});
|
369 | 374 | mmap{end}{2}(2)=pos-mmap{end}{2}(1);
|
|
382 | 387 | end
|
383 | 388 |
|
384 | 389 | if(varargin{1}.simplifycell)
|
385 |
| - if(iscell(object) && ~isempty(object) && (isnumeric(object{1}) || isstruct(object{1})) ) |
386 |
| - if(all(cellfun(@(e) isequal(size(object{1}), size(e)) , object(2:end)))) |
| 390 | + if(iscell(object) && ~isempty(object) && (all(cellfun(@isnumeric, object)) || all(cellfun(@isstruct, object)))) |
| 391 | + if(all(cellfun(@(e) isequal(size(object{1}), size(e)), object(2:end)))) |
387 | 392 | try
|
388 | 393 | oldobj=object;
|
389 | 394 | if(iscell(object) && length(object)>1 && ndims(object{1})>=2)
|
|
392 | 397 | object=cat(catdim,object{:});
|
393 | 398 | object=permute(object,ndims(object):-1:1);
|
394 | 399 | else
|
395 |
| - object=cell2mat(object')'; |
| 400 | + object=cell2mat(object.').'; |
396 | 401 | end
|
397 | 402 | if(iscell(oldobj) && isstruct(object) && numel(object)>1 && varargin{1}.simplifycellarray==0)
|
398 | 403 | object=oldobj;
|
|
402 | 407 | end
|
403 | 408 | end
|
404 | 409 | if(~iscell(object) && size(object,1)>1 && ndims(object)==2)
|
405 |
| - object=object'; |
| 410 | + object=object.'; |
406 | 411 | end
|
407 | 412 | end
|
408 | 413 | pos=parse_char(inputstr, pos, ']');
|
|
0 commit comments