Skip to content

Commit 30a842e

Browse files
author
Qianqian Fang
committed
update jsonlab towards v1.9 release
1 parent 2e317c9 commit 30a842e

File tree

9 files changed

+517
-383
lines changed

9 files changed

+517
-383
lines changed

ChangeLog.txt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,39 @@
66

77
JSONlab ChangeLog (key features marked by *):
88

9+
== JSONlab 1.9 (codename: Magnus - alpha), FangQ <q.fang <at> neu.edu> ==
10+
11+
2019-05-04 [2e317c9] explain extra compression fields
12+
2019-05-02 [1b1be65] avoid side effect of removing singletarray
13+
2019-05-02*[8360fd1] support zmat based base64 encoding and decoding
14+
2019-05-01*[c797bb2] integrating zmat, for zlib/gzip data compression
15+
2019-04-29 [70551fe] remove warnings from matlab
16+
2019-04-28 [0d61c4b] complete data compression support, close #52
17+
2019-04-27 [804115b] avoid typecast error
18+
2019-04-27 [c166aa7] change default compressarraysize to 100
19+
2019-04-27*[3322f6f] major new feature: support array compression and decompression
20+
2019-03-13*[9c01046] support saving function handles, close #51
21+
2019-03-13 [a8fde38] add option to parse string array or convert to char, close #50
22+
2019-03-12 [ed2645e] treat string array as cell array in newer matlab
23+
2018-11-18 [c3eb021] allow saving uint64 integers in saveubjson, fix #49
24+
25+
== JSONlab 1.8 (codename: Nominus), FangQ <q.fang <at> neu.edu> ==
26+
27+
2018-07-12 [03a6c25] update documentation, bump version to 1.8, tag Nominus
28+
2018-07-12*[1597106] add patch provided by pjkoprowski to support MATLAB table, add RowNames support, fix #29
29+
2018-07-12 [f16cc57] fix #31, throw an error when : array construct is used
30+
2018-07-12 [956e000] drop octave 3.x support, fix ubjson error in octave
31+
2018-07-12 [e090f0a] fix octave warning for saveubjson
32+
2018-07-12*[34284c7] fix issues #34 #39 #44 and #45, support double-quoted strings
33+
2017-09-06 [474d8c8] Merge pull request #41 from dasantonym/master
34+
2017-08-07*[38b24fb] added package.json to be able to intall via npm package manager, converted readme to utf-8, added basic .gitignore file
35+
2017-07-19 [ae7a5d9] Merge pull request #40 from astorfi/master
36+
2017-07-17 [154ef61] Rename README.txt to README.rst
37+
2017-03-27 [31b5bdc] simplify condition flow in matching_bracket
38+
2017-03-27 [86ef12a] avoid error in matlab 2017a, close #34
39+
2017-02-18 [4a09ac3] Merge pull request #32 from vrichter/master
40+
2017-02-14 [e67d3a3] respect integer types
41+
942
== JSONlab 1.5 (codename: Nominus - alpha), FangQ <q.fang <at> neu.edu> ==
1043

1144
2017/01/02 *use Big-endian format to store floating points (d/D) in saveubjson (Issue #25)
@@ -18,7 +51,7 @@ JSONlab ChangeLog (key features marked by *):
1851

1952
== JSONlab 1.2 (codename: Optimus - Update 2), FangQ <q.fang <at> neu.edu> ==
2053

21-
2015/12/16 replacing string concatenation by str cells to gain 2x speed in savejson (Issue#17)
54+
2015/12/16 *replacing string concatenation by str cells to gain 2x speed in savejson (Issue#17)
2255
2015/12/11 fix FileName option case bug (SVN rev#495)
2356
2015/12/11 add SingletCell option, add SingletArray to replace NoRowBracket (Issue#15,#8)
2457
2015/11/10 fix bug for inerpreting file names as JSON string - by Mykhailo Bratukha (Pull#14)

LICENSE_BSD.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2011-2018 Qianqian Fang <q.fang <at> neu.edu>. All rights reserved.
1+
Copyright 2011-2019 Qianqian Fang <q.fang <at> neu.edu>. All rights reserved.
22

33
Redistribution and use in source and binary forms, with or without modification, are
44
permitted provided that the following conditions are met:

LICENSE_GPLv3.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
= An open-source MATLAB/Octave JSON encoder and decoder =
44
===============================================================================
55

6-
Copyright (C) 2011-2018 Qianqian Fang <q.fang <at> neu.edu>
6+
Copyright (C) 2011-2019 Qianqian Fang <q.fang <at> neu.edu>
77

88
-------------------------------------------------------------------------------
99

README.rst

Lines changed: 339 additions & 313 deletions
Large diffs are not rendered by default.

README.txt

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
= An open-source MATLAB/Octave JSON encoder and decoder =
44
===============================================================================
55

6-
*Copyright (C) 2011-2018 Qianqian Fang <q.fang at neu.edu>
6+
*Copyright (C) 2011-2019 Qianqian Fang <q.fang at neu.edu>
77
*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)
99

1010
-------------------------------------------------------------------------------
1111

@@ -21,6 +21,13 @@ V. Contribution and feedback
2121

2222
I. Introduction
2323

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+
2431
JSON ([http://www.json.org/ JavaScript Object Notation]) is a highly portable,
2532
human-readable and "[http://en.wikipedia.org/wiki/JSON fat-free]" text format
2633
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
2936
of [http://en.wikipedia.org/wiki/Ajax_(programming) Ajax] and
3037
[http://en.wikipedia.org/wiki/Web_2.0 Web2.0].
3138

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
3340
optimized for compact file size and better performance while keeping
3441
the semantics as simple as the text-based JSON format. Using the UBJSON
3542
format allows to wrap complex binary data in a flexible and extensible
@@ -43,13 +50,6 @@ general-purpose file specifications, such as
4350
[http://www.hdfgroup.org/HDF5/whatishdf5.html HDF5], with significantly
4451
reduced complexity and enhanced performance.
4552

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-
5353
-------------------------------------------------------------------------------
5454

5555
II. Installation
@@ -62,10 +62,20 @@ by using the following command:
6262
addpath('/path/to/jsonlab');
6363

6464
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
6767
output, that means JSONLab is installed for MATLAB/Octave.
6868

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+
6979
-------------------------------------------------------------------------------
7080

7181
III.Using JSONLab
@@ -122,6 +132,7 @@ JSON. The detailed help info for the four functions can be found below:
122132
array of 1D vectors; setting to 4 will return a
123133
3D cell array.
124134
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.
125136

126137
output:
127138
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:
134145

135146
license:
136147
BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
137-
</pre>
148+
</pre>
138149

139150
=== savejson.m ===
140151

@@ -206,7 +217,22 @@ JSON. The detailed help info for the four functions can be found below:
206217
back to the string form
207218
opt.SaveBinary [0|1]: 1 - save the JSON file in binary mode; 0 - text mode.
208219
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.
210236
opt can be replaced by a list of ('param',value) pairs. The param
211237
string is equivallent to a field in opt and is case sensitive.
212238
output:
@@ -334,6 +360,23 @@ JSON. The detailed help info for the four functions can be found below:
334360
wrapped inside a function call as 'foo(...);'
335361
opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
336362
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.
337380

338381
opt can be replaced by a list of ('param',value) pairs. The param
339382
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,
399442
please download JSONLab source code from its source code repositories by using the
400443
following command:
401444

402-
git clone https://github.com/fangq/jsonlab.git jsonlab
445+
git clone https://github.com/fangq/jsonlab.git jsonlab
403446

404447
or browsing the github site at
405448

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
419450

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.
421456

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.
425466

426467
We appreciate any suggestions and feedbacks from you. Please use the following
427468
mailing list to report any questions you may have regarding JSONLab:
428469

429-
https://groups.google.com/forum/?hl=en#!forum/jsonlab-users
470+
https://groups.google.com/forum/?hl=en#!forum/iso2mesh-users
430471

431472
(Subscription to the mailing list is needed in order to post messages).

loadjson.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ function parse_char(inStr, c)
345345
pos = pos + 1;
346346
end
347347
end
348+
str=unescapejsonstring(str);
348349
error_pos('End of file while expecting end of inStr',inStr);
349350

350351
%%-------------------------------------------------------------------------
@@ -506,3 +507,11 @@ function error_pos(msg, inStr)
506507
if(endpos==0)
507508
error('unmatched "]"');
508509
end
510+
511+
function newstr=unescapejsonstring(str)
512+
newstr=str;
513+
escapechars={'\\','\"','\/','\a','\b','\f','\n','\r','\t','\v'};
514+
for i=1:length(escapechars);
515+
newstr=regexprep(newstr,regexprep(escapechars{i},'\\','\\\\'), escapechars{i});
516+
end
517+
newstr=regexprep(newstr,'\\\\(u[0-9a-fA-F]{4}[^0-9a-fA-F]*)','\\$1');

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonlab",
3-
"version": "1.5.0",
3+
"version": "1.9",
44
"description": "An open-source MATLAB/Octave JSON encoder and decoder",
55
"directories": {
66
"example": "examples"
@@ -17,5 +17,5 @@
1717
"bugs": {
1818
"url": "https://github.com/fangq/jsonlab/issues"
1919
},
20-
"homepage": "https://github.com/fangq/jsonlab#readme"
20+
"homepage": "https://iso2mesh.sf.net/jsonlab/"
2121
}

savejson.m

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,19 @@
6868
% opt.SaveBinary [0|1]: 1 - save the JSON file in binary mode; 0 - text mode.
6969
% opt.Compact [0|1]: 1- out compact JSON format (remove all newlines and tabs)
7070
% opt.Compression 'zlib' or 'gzip': specify array compression
71-
% method; currently only support 'gzip' or 'zlib'. The
72-
% data compression only applies to numerical arrays when
73-
% ArrayToStruct is 1. The compressed array use two extra
74-
% fields "_ArrayCompressionSize_" and "_ArrayCompressedData_"
75-
% where the former is a 1D interger array to store the
76-
% pre-compressed (but post-processed) array dimensions, and
77-
% the latter stores the "base64" encoded compressed binary
78-
% array data. In addition, an extra field
79-
% "_ArrayCompressionMethod_" stores the opt.Compression value.
71+
% method; currently only supports 'gzip' or 'zlib'. The
72+
% data compression only applicable to numerical arrays
73+
% in 3D or higher dimensions, or when ArrayToStruct
74+
% is 1 for 1D or 2D arrays. If one wants to
75+
% compress a long string, one must convert
76+
% it to uint8 or int8 array first. The compressed
77+
% array uses three extra fields
78+
% "_ArrayCompressionMethod_": the opt.Compression value.
79+
% "_ArrayCompressionSize_": a 1D interger array to
80+
% store the pre-compressed (but post-processed)
81+
% array dimensions, and
82+
% "_ArrayCompressedData_": the "base64" encoded
83+
% compressed binary array data.
8084
% opt.CompressArraySize [100|int]: only to compress an array if the total
8185
% element count is larger than this number.
8286
% opt can be replaced by a list of ('param',value) pairs. The param
@@ -118,20 +122,22 @@
118122
opt.IsOctave=exist('OCTAVE_VERSION','builtin');
119123

120124
dozip=jsonopt('Compression','',opt);
121-
if(~opt.IsOctave && ~isempty(dozip))
125+
if(~isempty(dozip))
122126
if(~(strcmpi(dozip,'gzip') || strcmpi(dozip,'zlib')))
123127
error('compression method "%s" is not supported',dozip);
124128
end
125-
try
126-
error(javachk('jvm'));
129+
if(exist('zmat')~=3)
127130
try
128-
base64decode('test');
131+
error(javachk('jvm'));
132+
try
133+
base64decode('test');
134+
catch
135+
matlab.net.base64decode('test');
136+
end
129137
catch
130-
matlab.net.base64decode('test');
138+
error('java-based compression is not supported');
131139
end
132-
catch
133-
error('java-based compression is not supported');
134-
end
140+
end
135141
opt.Compression=dozip;
136142
end
137143

@@ -202,7 +208,7 @@
202208
elseif(ischar(item))
203209
txt=str2json(name,item,level,varargin{:});
204210
elseif(isobject(item))
205-
if(~exist('OCTAVE_VERSION','builtin') && istable(item))
211+
if(~exist('OCTAVE_VERSION','builtin') && exist('istable','builtin') && istable(item))
206212
txt=matlabtable2json(name,item,level,varargin{:});
207213
else
208214
txt=matlabobject2json(name,item,level,varargin{:});
@@ -403,10 +409,6 @@
403409
dozip=jsonopt('Compression','',varargin{:});
404410
zipsize=jsonopt('CompressArraySize',100,varargin{:});
405411

406-
if(islogical(item))
407-
item=uint8(item);
408-
end
409-
410412
if(length(size(item))>2 || issparse(item) || ~isreal(item) || ...
411413
(isempty(item) && any(size(item))) ||jsonopt('ArrayToStruct',0,varargin{:}) || (~isempty(dozip) && numel(item)>zipsize))
412414
if(isempty(name))
@@ -487,6 +489,9 @@
487489
if(~isempty(dozip) && numel(item)>zipsize)
488490
if(isreal(item))
489491
fulldata=item(:)';
492+
if(islogical(fulldata))
493+
fulldata=uint8(fulldata);
494+
end
490495
else
491496
txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep);
492497
fulldata=[real(item(:)) imag(item(:))];

0 commit comments

Comments
 (0)