3
3
= An open-source MATLAB/Octave JSON encoder and decoder =
4
4
===============================================================================
5
5
6
- *Copyright (C) 2011-2018 Qianqian Fang <q.fang at neu.edu>
6
+ *Copyright (C) 2011-2019 Qianqian Fang <q.fang at neu.edu>
7
7
*License: BSD or GNU General Public License version 3 (GPL v3), see License*.txt
8
- *Version: 1.8 (Nominus )
8
+ *Version: 1.9 (Magnus - alpha )
9
9
10
10
-------------------------------------------------------------------------------
11
11
@@ -21,6 +21,13 @@ V. Contribution and feedback
21
21
22
22
I. Introduction
23
23
24
+ JSONLab is a free and open-source implementation of a JSON/UBJSON encoder
25
+ and a decoder in the native MATLAB language. It can be used to convert a MATLAB
26
+ data structure (array, struct, cell, struct array and cell array) into
27
+ JSON/UBJSON formatted strings, or to decode a JSON/UBJSON file into MATLAB
28
+ data structure. JSONLab supports both MATLAB and
29
+ [http://www.gnu.org/software/octave/ GNU Octave] (a free MATLAB clone).
30
+
24
31
JSON ([http://www.json.org/ JavaScript Object Notation]) is a highly portable,
25
32
human-readable and "[http://en.wikipedia.org/wiki/JSON fat-free]" text format
26
33
to represent complex and hierarchical data. It is as powerful as
@@ -29,7 +36,7 @@ used for data-exchange in applications, and is essential for the wild success
29
36
of [http://en.wikipedia.org/wiki/Ajax_(programming) Ajax] and
30
37
[http://en.wikipedia.org/wiki/Web_2.0 Web2.0].
31
38
32
- UBJSON (Universal Binary JSON) is a binary JSON format, specifically
39
+ UBJSON ([<http://ubjson.org/ Universal Binary JSON] ) is a binary JSON format, specifically
33
40
optimized for compact file size and better performance while keeping
34
41
the semantics as simple as the text-based JSON format. Using the UBJSON
35
42
format allows to wrap complex binary data in a flexible and extensible
@@ -43,13 +50,6 @@ general-purpose file specifications, such as
43
50
[http://www.hdfgroup.org/HDF5/whatishdf5.html HDF5], with significantly
44
51
reduced complexity and enhanced performance.
45
52
46
- JSONLab is a free and open-source implementation of a JSON/UBJSON encoder
47
- and a decoder in the native MATLAB language. It can be used to convert a MATLAB
48
- data structure (array, struct, cell, struct array and cell array) into
49
- JSON/UBJSON formatted strings, or to decode a JSON/UBJSON file into MATLAB
50
- data structure. JSONLab supports both MATLAB and
51
- [http://www.gnu.org/software/octave/ GNU Octave] (a free MATLAB clone).
52
-
53
53
-------------------------------------------------------------------------------
54
54
55
55
II. Installation
@@ -62,10 +62,20 @@ by using the following command:
62
62
addpath('/path/to/jsonlab');
63
63
64
64
If you want to add this path permanently, you need to type "pathtool",
65
- browse to the jsonlab root folder and add to the list, then click "Save".
66
- Then, run "rehash" in MATLAB, and type "which loadjson ", if you see an
65
+ browse to the zmat root folder and add to the list, then click "Save".
66
+ Then, run "rehash" in MATLAB, and type "which savejson ", if you see an
67
67
output, that means JSONLab is installed for MATLAB/Octave.
68
68
69
+ If you use MATLAB in a shared environment such as a Linux server, the
70
+ best way to add path is to type
71
+
72
+ mkdir ~/matlab/
73
+ nano ~/matlab/startup.m
74
+
75
+ and type addpath('/path/to/jsonlab') in this file, save and quit the editor.
76
+ MATLAB will execute this file every time it starts. For Octave, the file
77
+ you need to edit is ~/.octaverc , where "~" is your home directory.
78
+
69
79
-------------------------------------------------------------------------------
70
80
71
81
III.Using JSONLab
@@ -122,6 +132,7 @@ JSON. The detailed help info for the four functions can be found below:
122
132
array of 1D vectors; setting to 4 will return a
123
133
3D cell array.
124
134
opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar.
135
+ opt.ParseStringArray [0|1]: if set to 1, loadjson displays a progress bar.
125
136
126
137
output:
127
138
dat: a cell array, where {...} blocks are converted into cell arrays,
@@ -134,7 +145,7 @@ JSON. The detailed help info for the four functions can be found below:
134
145
135
146
license:
136
147
BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
137
- </pre>
148
+ </pre>
138
149
139
150
=== savejson.m ===
140
151
@@ -206,7 +217,22 @@ JSON. The detailed help info for the four functions can be found below:
206
217
back to the string form
207
218
opt.SaveBinary [0|1]: 1 - save the JSON file in binary mode; 0 - text mode.
208
219
opt.Compact [0|1]: 1- out compact JSON format (remove all newlines and tabs)
209
-
220
+ opt.Compression 'zlib' or 'gzip': specify array compression
221
+ method; currently only supports 'gzip' or 'zlib'. The
222
+ data compression only applicable to numerical arrays
223
+ in 3D or higher dimensions, or when ArrayToStruct
224
+ is 1 for 1D or 2D arrays. If one wants to
225
+ compress a long string, one must convert
226
+ it to uint8 or int8 array first. The compressed
227
+ array uses three extra fields
228
+ "_ArrayCompressionMethod_": the opt.Compression value.
229
+ "_ArrayCompressionSize_": a 1D interger array to
230
+ store the pre-compressed (but post-processed)
231
+ array dimensions, and
232
+ "_ArrayCompressedData_": the "base64" encoded
233
+ compressed binary array data.
234
+ opt.CompressArraySize [100|int]: only to compress an array if the total
235
+ element count is larger than this number.
210
236
opt can be replaced by a list of ('param',value) pairs. The param
211
237
string is equivallent to a field in opt and is case sensitive.
212
238
output:
@@ -334,6 +360,23 @@ JSON. The detailed help info for the four functions can be found below:
334
360
wrapped inside a function call as 'foo(...);'
335
361
opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
336
362
back to the string form
363
+ opt.Compression 'zlib' or 'gzip': specify array compression
364
+ method; currently only supports 'gzip' or 'zlib'. The
365
+ data compression only applicable to numerical arrays
366
+ in 3D or higher dimensions, or when ArrayToStruct
367
+ is 1 for 1D or 2D arrays. If one wants to
368
+ compress a long string, one must convert
369
+ it to uint8 or int8 array first. The compressed
370
+ array uses three extra fields
371
+ "_ArrayCompressionMethod_": the opt.Compression value.
372
+ "_ArrayCompressionSize_": a 1D interger array to
373
+ store the pre-compressed (but post-processed)
374
+ array dimensions, and
375
+ "_ArrayCompressedData_": the binary stream of
376
+ the compressed binary array data WITHOUT
377
+ 'base64' encoding
378
+ opt.CompressArraySize [100|int]: only to compress an array if the total
379
+ element count is larger than this number.
337
380
338
381
opt can be replaced by a list of ('param',value) pairs. The param
339
382
string is equivallent to a field in opt and is case sensitive.
@@ -399,33 +442,31 @@ that everyone else can enjoy the improvement. For anyone who want to contribute,
399
442
please download JSONLab source code from its source code repositories by using the
400
443
following command:
401
444
402
- git clone https://github.com/fangq/jsonlab.git jsonlab
445
+ git clone https://github.com/fangq/jsonlab.git jsonlab
403
446
404
447
or browsing the github site at
405
448
406
- https://github.com/fangq/jsonlab
407
-
408
- alternatively, if you prefer svn, you can checkout the latest code by using
409
-
410
- svn checkout svn://svn.code.sf.net/p/iso2mesh/code/trunk/jsonlab jsonlab
411
-
412
- You can make changes to the files as needed. Once you are satisfied with your
413
- changes, and ready to share it with others, please cd the root directory of
414
- JSONLab, and type
415
-
416
- git diff --no-prefix > yourname_featurename.patch
417
-
418
- or
449
+ https://github.com/fangq/jsonlab
419
450
420
- svn diff > yourname_featurename.patch
451
+ Sometimes, you may find it is necessary to modify JSONLab to achieve your
452
+ goals, or attempt to modify JSONLab functions to fix a bug that you have
453
+ encountered. If you are happy with your changes and willing to share those
454
+ changes to the upstream author, you are recommended to create a pull-request
455
+ on github.
421
456
422
- You then email the .patch file to JSONLab's maintainer, Qianqian Fang, at
423
- the email address shown in the beginning of this file. Qianqian will review
424
- the changes and commit it to the subversion if they are satisfactory.
457
+ To create a pull-request, you first need to "fork" jsonlab on Github by
458
+ clicking on the "fork" button on top-right of jsonlab's github page. Once you forked
459
+ jsonlab to your own directory, you should then implement the changes in your
460
+ own fork. After thoroughly testing it and you are confident the modification
461
+ is complete and effective, you can then click on the "New pull request"
462
+ button, and on the left, select fangq/jsonlab as the "base". Then type
463
+ in the description of the changes. You are responsible to format the code
464
+ updates using the same convention (tab-width: 8, indentation: 4 spaces) as
465
+ the upstream code.
425
466
426
467
We appreciate any suggestions and feedbacks from you. Please use the following
427
468
mailing list to report any questions you may have regarding JSONLab:
428
469
429
- https://groups.google.com/forum/?hl=en#!forum/jsonlab -users
470
+ https://groups.google.com/forum/?hl=en#!forum/iso2mesh -users
430
471
431
472
(Subscription to the mailing list is needed in order to post messages).
0 commit comments