Skip to content

Commit e1c21b3

Browse files
committed
[doc] update jdict help info
1 parent feaced6 commit e1c21b3

1 file changed

Lines changed: 32 additions & 27 deletions

File tree

jdict.m

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
% author: Qianqian Fang (q.fang <at> neu.edu)
99
%
1010
% input:
11-
% data: a hierachical data structure made of struct, containers.Map, dictionary, or cell arrays
12-
% if data is a string starting with http:// or https://,
13-
% loadjson(data) will be used to dynamically load the data
11+
% data: an array, or hierachical data structure made of struct,
12+
% containers.Map, dictionary, or cell arrays; if data is a
13+
% string starting with http:// or https://, loadjson(data)
14+
% will be used to dynamically load the data
1415
%
1516
% indexing:
16-
% jd.('key1').('subkey1')... can retrieve values that are recursively index keys that are
17+
% jd.('key1').('subkey1')... can retrieve values that are recursively index keys
1718
% jd.key1.subkey1... can also retrieve the same data regardless
1819
% if the underlying data is struct, containers.Map or dictionary
1920
% jd.('key1').('subkey1').v(1) if the subkey key1 is an array, this can retrieve the first element
@@ -26,11 +27,12 @@
2627
% member functions:
2728
% jd() or jd.v() returns the underlying hierachical data
2829
% jd.('cell1').v(i) or jd.('array1').v(2:3) returns specified elements if the element is a cell or array
29-
% jd.('key1'),('subkey1').v() returns the underlying hierachical data at the specified subkeys
30+
% jd.('key1').('subkey1').v() returns the underlying hierachical data at the specified subkeys
3031
% jd.tojson() convers the underlying data to a JSON string
3132
% jd.tojson('compression', 'zlib', ...) convers the data to a JSON string with savejson() options
3233
% jd.keys() return the sub-key names of the object - if it a struct, dictionary or containers.Map - or 1:length(data) if it is an array
3334
% jd.len() return the length of the sub-keys
35+
% jd.size() return the dimension vector
3436
% jd{'attrname'} get/set attributes using curly brace indexing
3537
% jd.setattr(jsonpath, attrname, value) set attribute at any path
3638
% jd.getattr(jsonpath, attrname) get attribute from any path
@@ -39,20 +41,22 @@
3941
% brackets .(...), but in octave, one must use .v(...)
4042
%
4143
% examples:
42-
% obj = struct('key1', struct('subkey1',1, 'subkey2',[1,2,3]), 'subkey2', 'str');
43-
% obj.key1.subkey3 = {8,'test',containers.Map('subsubkey1',0)};
4444
%
45-
% jd = jdict(obj);
45+
% jd = jdict;
46+
% jd.key1 = struct('subkey1',1, 'subkey2',[1,2,3]);
47+
% jd.key2 = 'str';
48+
% jd.key1.subkey3 = {8,'test',containers.Map('special key',10)};
4649
%
4750
% % getting values
4851
% jd() % return obj
49-
% jd.('key1').('subkey1') % return jdict(1)
50-
% jd.keys.subkey1 % return jdict(1)
51-
% jd.('key1').('subkey3') % return jdict(obj.key1.subkey3)
52-
% jd.('key1').('subkey3')() % return obj.key1.subkey3
53-
% jd.('key1').('subkey3').v(1) % return jdict({8})
54-
% jd.('key1').('subkey3').('subsubkey1') % return jdict(obj.key1.subkey3(2))
55-
% jd.('key1').('subkey3').v(2).v() % return {'test'}
52+
% jd.key1.subkey1 % return jdict(1)
53+
% jd.('key1').('subkey1') % same as above
54+
% jd.key1.('subkey1') % same as above
55+
% jd.key1.subkey3 % return jdict(obj.key1.subkey3)
56+
% jd.key1.subkey3() % return obj.key1.subkey3
57+
% jd.key1.subkey3.v(1) % return jdict(8)
58+
% jd.key1.subkey3.v(3).('special key') % return jdict(10)
59+
% jd.key1.subkey3.v(2).v() % return 'test'
5660
% jd.('$.key1.subkey1') % return jdict(1)
5761
% jd.('$.key1.subkey2')() % return 'str'
5862
% jd.('$.key1.subkey2').v().v(1) % return jdict(1)
@@ -62,22 +66,23 @@
6266
% jd.('$..subkey2').v(2) % return jdict([1,2,3])
6367
%
6468
% % setting values
65-
% jd.('subkey2') = 'newstr' % setting obj.subkey2 to 'newstr'
66-
% jd.('key1').('subkey2').v(1) = 2; % modify indexed element
67-
% jd.('key1').('subkey2').v([2, 3]) = [10, 11]; % modify multiple values
68-
% jd.('key1').('subkey3').v(3).('subsubkey1') = 1; % modify keyed value
69-
% jd.('key1').('subkey3').v(3).('subsubkey2') = 'new'; % add new key
69+
% jd.subkey2 = 'newstr' % setting obj.subkey2 to 'newstr'
70+
% jd.key1.subkey2.v(1) = 2; % modify indexed element
71+
% jd.key1.subkey2.v([2, 3]) = [10, 11]; % modify multiple values
72+
% jd.key1.subkey3.v(3).('special key') = 1; % modify keyed value
73+
% jd.key1.newkey = 'new'; % add new key
7074
%
7175
% % attributes
72-
% jd{'dims'} = {'x','y','z'}; % set attribute
73-
% %% {'attr'} is MATLAB-only
74-
% jd.('a'){'dims'} = {'time','space'}; % set attribute on nested element(MATLAB only, Octave use .setattr())
75-
% %% use .setattr() in MATLAB/Octave
76-
% jd.('a').setattr('dims',{'time','space'}); % set attributes
77-
% jd.('a'){'dims'} % print attribute on nested element
76+
% jd.vol = zeros(2,3,4); % set 3d arrays
77+
% jd.vol{'dims'} = {'x','y','z'}; % set dimension labels (MATLAB-only)
78+
% jd.vol.setattr('dims', {'x','y','z'}); % set attribute in Octave
79+
% jd.vol{'dims'} % print dimension names
80+
% jd.vol{'units'} = 'mm'; % set any custom attributes
81+
% jd.vol.getattr('units') % retrieve attributes
82+
% jd.vol.getattr() % list all attribute paths
7883
%
7984
% % loading complex data from REST-API
80-
% jd = jdict('https://neurojson.io:7777/cotilab/NeuroCaptain_2024');
85+
% jd = jdict('https://neurojson.io:7777/cotilab/NeuroCaptain_2025');
8186
%
8287
% jd.('Atlas_Age_19_0')
8388
% jd.Atlas_Age_19_0.('Landmark_10_10').('$.._DataLink_')

0 commit comments

Comments
 (0)