Skip to content

Commit 2e3344c

Browse files
committed
[Breaking] use little-endian for all BJData numeric,fix BJData ND array order,prepare 3.0-beta
1 parent 632531f commit 2e3344c

20 files changed

+471
-271
lines changed

AUTHORS.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The author of "jsonlab" toolbox is Qianqian Fang. Qianqian is
1+
The author of "JSONLab" toolbox is Qianqian Fang. Dr. Fang is
22
currently an Associate Professor in the Department of Bioengineering,
33
Northeastern University, USA.
44

@@ -8,10 +8,16 @@ Address: Qianqian Fang
88
ISEC 206
99
360 Huntington Ave, Boston, MA 02115, USA
1010
Phone[O]: 617-373-3829
11-
URL: http://fanglab.org
11+
URL: http://fanglab.org, http://neurojson.org
1212
Email: <q.fang at neu.edu> and <fangqq at gmail.com>
1313

1414

15+
Since 2021, this project has been partially funded by the USA National Institute of Health (NIH)
16+
and National Institute of Neurological Disorders and Stroke (NINDS) under grant
17+
U24-NS124027 (PI Qianqian Fang). It is the reference implementation of the JData
18+
and BJData specifications developed under the NeuroJSON Project (http://neurojson.org).
19+
20+
1521
The script loadjson.m was built upon previous works (BSD 3-clause license) by
1622

1723
- Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
@@ -37,7 +43,7 @@ The loadmsgpack.m script was modified from
3743
This toolbox contains patches submitted by the following contributors:
3844

3945
- Blake Johnson <bjohnso at bbn.com>
40-
part of revision 341
46+
part of svn revision 341
4147

4248
- Niclas Borlin <Niclas.Borlin at cs.umu.se>
4349
various fixes in revision 394, including

ChangeLog.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55
----------------------------------------------------------------------------
66

77
JSONlab ChangeLog (key features marked by *):
8+
== JSONlab 2.9.8 (codename: Micronus Prime - beta), FangQ <q.fang (at) neu.edu> ==
9+
10+
2022-01-30*[ ] [bjdata:breaking] Upgrade savebj/loadbj to BJData v1-draft 2, use little-endian by default
11+
2022-01-30*[ ] [bjdata:breaking] Fix optimized ND array element order (previously used column-major)
12+
2022-01-30*[ ] optimize loadjson and loadbj speed
13+
2022-01-30*[ ] add 'BuiltinJSON' option for savejson/loadjson to call jsonencode/jsondecode
14+
2022-01-30*[ ] more robust tests on ND array when parsing JSON numerical array construct
15+
2021-06-23 [632531f] fix inconsistency between singlet integer and float values, close #70
16+
2021-06-23 [f7d8226] prevent function calls when parsing array strings using eval, fix #75
17+
2021-06-23 [b1ae5fa] fix #73 as a regression to #22
18+
2020-09-29 [d0cb3b8] Fix for loading objects.
19+
2020-07-26 [d0fb684] Add travis badge
20+
2020-07-25 [708c36c] drop octave 3.2
21+
2020-07-25 [436d84e] debug octave 3.2
22+
2020-07-25 [0ce96ec] remove windows and osx targets from travis-ci
23+
2020-07-25 [0d8baa4] fix ruby does not support error on windows
24+
2020-07-25*[faa7921] enable travis-ci for jsonlab
25+
2020-07-08 [321ab1a] add Debian and Ubuntu installation commands
26+
2020-07-08 [e686828] update author info
27+
2020-07-08*[ce40fdf] supports ND cell array, fix #66
28+
2020-07-07 [6a8ce93] fix string encoding over 399 characters, close #65
29+
2020-06-14 [5a58faf] fix DESCRIPTION date bug
30+
2020-06-14 [9d7e94c] match octave description file and upstream version number
31+
2020-06-14 [a5b6170] fix warning about lz4encode file name
832

933
== JSONlab 2.0 (codename: Magnus Prime), FangQ <q.fang (at) neu.edu> ==
1034

Contents.m

Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@
230230
% JDataDecode [1|0]: if set to 1, call jdatadecode to decode
231231
% JData structures defined in the JData
232232
% Specification.
233+
% BuiltinJSON [0|1]: if set to 1, this function attempts to call
234+
% jsondecode, if presents (MATLAB R2016b or Octave
235+
% 6) first. If jsondecode does not exist or failed,
236+
% this function falls back to the jsonlab parser
233237
%
234238
% output:
235239
% dat: a cell array, where {...} blocks are converted into cell arrays,
@@ -347,6 +351,10 @@
347351
% 'b': big endian, 'l': little-endian)
348352
% PreEncode [1|0]: if set to 1, call jdataencode first to preprocess
349353
% the input data before saving
354+
% BuiltinJSON [0|1]: if set to 1, this function attempts to call
355+
% jsonencode, if presents (MATLAB R2016b or Octave
356+
% 6) first. If jsonencode does not exist or failed,
357+
% this function falls back to the jsonlab savejson
350358
%
351359
% opt can be replaced by a list of ('param',value) pairs. The param
352360
% string is equivallent to a field in opt and is case sensitive.
@@ -375,9 +383,16 @@
375383
% or
376384
% data=loadbj(fname,'param1',value1,'param2',value2,...)
377385
%
378-
% Parse a Binary JData (BJData v1 Draft-1, defined in https://github.com/OpenJData/bjdata)
386+
% Parse a Binary JData (BJData v1 Draft-2, defined in https://github.com/NeuroJSON/bjdata)
379387
% file or memory buffer and convert into a MATLAB data structure
380388
%
389+
% By default, this function parses BJD-compliant output. The BJD
390+
% specification is largely similar to UBJSON, with additional data types
391+
% including uint16(u), uint32(m), uint64(M) and half-precision float (h).
392+
% Starting from BJD Draft-2 (JSONLab 3.0 beta or later), all integer and
393+
% floating-point numbers are parsed in Little-Endian as opposed to
394+
% Big-Endian form as in BJD Draft-1/UBJSON Draft-12 (JSONLab 2.1 or older)
395+
%
381396
% initially created on 2013/08/01
382397
%
383398
% input:
@@ -391,16 +406,26 @@
391406
% SimplifyCell [1|0]: if set to 1, loadbj will call cell2mat
392407
% for each element of the JSON data, and group
393408
% arrays based on the cell2mat rules.
394-
% IntEndian [B|L]: specify the endianness of the integer fields
395-
% in the BJData/UBJSON input data. B - Big-Endian format for
396-
% integers (as required in the UBJSON specification);
397-
% L - input integer fields are in Little-Endian order.
409+
% Endian ['L'|'B']: specify the endianness of the numbers
410+
% in the BJData/UBJSON input data. Default: 'L'.
411+
%
412+
% Starting from JSONLab 2.9, BJData by default uses
413+
% [L] Little-Endian for both integers and floating
414+
% point numbers. This is a major departure from the
415+
% UBJSON specification, where 'B' - Big-Endian -
416+
% format is used for integer fields. UBJSON does
417+
% not specifically define Endianness for
418+
% floating-point numbers, resulting in mixed
419+
% implementations. JSONLab 2.0-2.1 used 'B' for
420+
% integers and floating-points; JSONLab 1.x uses
421+
% 'B' for integers and native-endianness for
422+
% floating-point numbers.
398423
% NameIsString [0|1]: for UBJSON Specification Draft 8 or
399424
% earlier versions (JSONLab 1.0 final or earlier),
400425
% the "name" tag is treated as a string. To load
401426
% these UBJSON data, you need to manually set this
402427
% flag to 1.
403-
% UseMap [0|1]: if set to 1, loadjson uses a containers.Map to
428+
% UseMap [0|1]: if set to 1, loadbj uses a containers.Map to
404429
% store map objects; otherwise use a struct object
405430
% ObjectID [0|interger or list]: if set to a positive number,
406431
% it returns the specified JSON object by index
@@ -436,17 +461,20 @@
436461
% bjd=savebj(rootname,obj,'param1',value1,'param2',value2,...)
437462
%
438463
% Convert a MATLAB object (cell, struct, array, table, map, handles ...)
439-
% into a Binary JData (BJData v1 Draft-1), Universal Binary JSON (UBJSON,
464+
% into a Binary JData (BJData v1 Draft-2), Universal Binary JSON (UBJSON,
440465
% Draft-12) or a MessagePack binary stream
441466
%
442467
% initially created on 2013/08/17
443468
%
444469
% By default, this function creates BJD-compliant output. The BJD
445470
% specification is largely similar to UBJSON, with additional data types
446-
% including uint16(u), uint32(m), uint64(M) and half-precision float (h)
471+
% including uint16(u), uint32(m), uint64(M) and half-precision float (h).
472+
% Starting from BJD Draft-2 (JSONLab 3.0 beta or later), all integer and
473+
% floating-point numbers are stored in Little-Endian as opposed to
474+
% Big-Endian form as in BJD Draft-1/UBJSON Draft-12 (JSONLab 2.1 or older)
447475
%
448476
% Format specifications:
449-
% Binary JData (BJD): https://github.com/fangq/bjdata
477+
% Binary JData (BJD): https://github.com/NeuroJSON/bjdata
450478
% UBJSON: https://github.com/ubjson/universal-binary-json
451479
% MessagePack: https://github.com/msgpack/msgpack
452480
%
@@ -524,7 +552,8 @@
524552
% UBJSON [0|1]: 0: (default)-encode data based on BJData Draft 1
525553
% (supports uint16(u)/uint32(m)/uint64(M)/half(h) markers)
526554
% 1: encode data based on UBJSON Draft 12 (without
527-
% u/m/M/h markers)
555+
% u/m/M/h markers);all numeric values are stored in
556+
% the Big-Endian byte order according to Draft-12
528557
% FormatVersion [2|float]: set the JSONLab output version; since
529558
% v2.0, JSONLab uses JData specification Draft 3
530559
% for output format, it is incompatible with releases
@@ -535,7 +564,21 @@
535564
% of the minimum length without losing accuracy (default)
536565
% Debug [0|1]: output binary numbers in <%g> format for debugging
537566
% Append [0|1]: if set to 1, append a new object at the end of the file.
538-
% Endian ['n'|'b','l']: Endianness of the output file ('n': native,
567+
% Endian ['L'|'B']: specify the endianness of the numbers
568+
% in the BJData/UBJSON input data. Default: 'L'.
569+
%
570+
% Starting from JSONLab 2.9, BJData by default uses
571+
% [L] Little-Endian for both integers and floating
572+
% point numbers. This is a major departure from the
573+
% UBJSON specification, where 'B' - Big-Endian -
574+
% format is used for integer fields. UBJSON does
575+
% not specifically define Endianness for
576+
% floating-point numbers, resulting in mixed
577+
% implementations. JSONLab 2.0-2.1 used 'B' for
578+
% integers and floating-points; JSONLab 1.x uses
579+
% 'B' for integers and native-endianness for
580+
% floating-point numbers.
581+
% FileEndian ['n'|'b','l']: Endianness of the output file ('n': native,
539582
% 'b': big endian, 'l': little-endian)
540583
% PreEncode [1|0]: if set to 1, call jdataencode first to preprocess
541584
% the input data before saving
@@ -553,6 +596,7 @@
553596
% 'MeshCreator','FangQ','MeshTitle','T6 Cube',...
554597
% 'SpecialData',[nan, inf, -inf]);
555598
% savebj(jsonmesh)
599+
% savebj('',jsonmesh,'debug',1)
556600
% savebj('',jsonmesh,'meshdata.bjd')
557601
% savebj('mesh1',jsonmesh,'FileName','meshdata.msgpk','MessagePack',1)
558602
% savebj('',jsonmesh,'ubjson',1)
@@ -576,8 +620,9 @@
576620
% This function is an alias to loadbj
577621
%
578622
% input:
579-
% fname: input file name, if fname contains "{}" or "[]", fname
580-
% will be interpreted as a UBJSON string
623+
% fname: input file name, if the file with such name exists, it will
624+
% be read, otherwise, this function will attempt to parse the
625+
% string in fname as a UBJSON stream
581626
% opt: a struct to store parsing options, opt can be replaced by
582627
% a list of ('param',value) pairs - the param string is equivallent
583628
% to a field in opt. The supported options can be found by typing
@@ -606,20 +651,21 @@
606651
% ubj=saveubjson(rootname,obj,opt)
607652
% ubj=saveubjson(rootname,obj,'param1',value1,'param2',value2,...)
608653
%
609-
% Convert a MATLAB object (cell, struct, array, table, map, handles ...)
610-
% into a Universal Binary JSON (UBJSON, Draft 12) or a MessagePack binary stream
654+
% Convert a MATLAB object (cell, struct, array, table, map, graphs ...)
655+
% into a Universal Binary JSON (UBJSON, Draft-12) or a MessagePack binary stream
611656
%
612657
% initially created on 2013/08/17
613658
%
614659
% Format specifications:
615-
% Binary JData (BJData):https://github.com/fangq/bjdata
660+
% Binary JData (BJData):https://github.com/NeuroJSON/bjdata
616661
% UBJSON: https://github.com/ubjson/universal-binary-json
617662
% MessagePack: https://github.com/msgpack/msgpack
618663
%
619-
% This function is the same as calling "savebj(...,'ubjson',1)". By ,
620-
% default this function creates UBJSON-compliant output without the
664+
% This function is the same as calling "savebj(..,'ubjson',1,'endian','B')"
665+
% By default this function creates UBJSON-compliant output without the
621666
% newly added uint16(u), uint32(m), uint64(M) and half-precision float (h)
622-
% data types.
667+
% data types and use Big-Endian for all numerical values as in UBJSON
668+
% Draft-12.
623669
%
624670
% This function by default still enables an optimized ND-array format for efficient
625671
% array storage. To ensure the output compatible to UBJSON Draft-12, one should use
@@ -641,7 +687,7 @@
641687
% Please type "help savebj" for details for all supported options.
642688
%
643689
% output:
644-
% json: a binary string in the UBJSON format (see http://ubjson.org)
690+
% ubj: a binary string in the UBJSON format (see http://ubjson.org)
645691
%
646692
% examples:
647693
% jsonmesh=struct('MeshVertex3',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],...
@@ -720,7 +766,7 @@
720766
% fname: (optional) output file name; if not given, save to 'jamdata.jamm'
721767
% if fname has a '.json' or '.jdt' suffix, a text-based
722768
% JSON/JData file will be created (slow); if the suffix is '.jamm' or
723-
% '.jdb', a Binary JData (https://github.com/fangq/bjdata/) file will be created.
769+
% '.jdb', a Binary JData (https://github.com/NeuroJSON/bjdata/) file will be created.
724770
% opt: (optional) a struct to store parsing options, opt can be replaced by
725771
% a list of ('param',value) pairs - the param string is equivallent
726772
% to a field in opt. opt can have the following
@@ -780,7 +826,7 @@
780826
% parse the json file and then decode the output by
781827
% jdatadecode; input file must have a suffix of .jdt
782828
%
783-
% all options for loadubjson/loadjson (depends on file suffix)
829+
% all options for loadbj/loadjson (depends on file suffix)
784830
% can be used to adjust the parsing options
785831
%
786832
% output:
@@ -1033,7 +1079,7 @@
10331079
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
10341080
%
10351081

1036-
%==== function varargout = lz4hcencode(varargin) ====
1082+
%==== function varargout = lz4encode(varargin) ====
10371083
%
10381084
% output = lz4encode(input)
10391085
% or
@@ -1392,9 +1438,9 @@
13921438
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
13931439
%
13941440

1395-
%==== function [dims, maxlevel, count] = nestbracket2dim(str,brackets) ====
1441+
%==== function [dims, isndarray, maxlevel, count] = nestbracket2dim(str,brackets,testndarray) ====
13961442
%
1397-
% [dims, maxlevel, count] = nestbracket2dim(str,brackets)
1443+
% [dims, isndarray, maxlevel, count] = nestbracket2dim(str,brackets)
13981444
%
13991445
% Extracting the dimension vector of a JSON string formatted array
14001446
% by analyzing the pairs of opening/closing bracket tokenss; this function
@@ -1409,12 +1455,17 @@
14091455
% if not given, brackets is set to '[]' to find matching square-brackets;
14101456
% for example, '{}' looks for a matching closing curly-bracket in
14111457
% the string key(pos(startpos,:end))
1458+
% testndarray: (optional), 1 to test if the input string contains an
1459+
% ND array, i.e. with uniform element lengths (recursively)
14121460
%
14131461
% output:
14141462
% dims: the speculated dimension vector with the length matching the maximum
14151463
% depth of the embedded bracket pairs. When the input string encodes an
14161464
% N-D array, the dims vector contains all integers; however, returning
1417-
% an all-integer dims vector does not mean the array is rectangular.
1465+
% an all-integer dims vector does not mean the array is
1466+
% rectangular. if testndarray is set to 1, dims returns isndarray
1467+
% isndarray: 1 to indicate the input string contains an ND array,
1468+
% otherwise, 0
14181469
% maxlevel: return the depth of the enclosed brackets in the string, i.e. the
14191470
% length of the dims vector.
14201471
% count: the relative depth from the level 0 - scanning from the left

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: jsonlab
2-
Version: 2.0
3-
Date: 2020-13-06
2+
Version: 2.9.8
3+
Date: 2022-30-01
44
Title: A JSON/UBJSON/MessagePack encoder/decoder for MATLAB/Octave
55
Author: Qianqian Fang <[email protected]>
66
Maintainer: Qianqian Fang <[email protected]>

LICENSE_BSD.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2011-2020 Qianqian Fang <q.fang at neu.edu>
1+
Copyright (c) 2011-2022 Qianqian Fang <q.fang at neu.edu>
22
Copyright (c) 2014,2016 Bastian Bechtold
33
Copyright (c) 2012, Kota Yamaguchi
44
Copyright (c) 2009, Nedialko Krouchev

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

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

0 commit comments

Comments
 (0)