diff --git a/ChangeLog.txt b/ChangeLog.txt index 6478f883299515745390744e7d40cdcbdb714335..07824f5c3f6e541c35a6b50b8156539683886aac 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,11 @@ JSONlab ChangeLog (key features marked by *): +== JSONlab 1.0 (codename: Optimus - Final), FangQ <fangq (at) nmr.mgh.harvard.edu> == + + 2015/01/02 polish help info for all major functions, update examples, finalize 1.0 + 2014/12/19 fix a bug to strictly respect NoRowBracket in savejson + == JSONlab 1.0.0-RC2 (codename: Optimus - RC2), FangQ <fangq (at) nmr.mgh.harvard.edu> == 2014/11/22 show progress bar in loadjson ('ShowProgress') diff --git a/README.txt b/README.txt index ca027bf01a7c8e48963f846d7dd39a309b0710aa..206888984aba3607bbc8344060d0c2cbd6c6f161 100644 --- a/README.txt +++ b/README.txt @@ -1,11 +1,11 @@ =============================================================================== -= JSONlab = += JSONLab = = An open-source MATLAB/Octave JSON encoder and decoder = =============================================================================== -*Copyright (C) 2011-2014 Qianqian Fang <fangq at nmr.mgh.harvard.edu> +*Copyright (C) 2011-2015 Qianqian Fang <fangq at nmr.mgh.harvard.edu> *License: BSD or GNU General Public License version 3 (GPL v3), see License*.txt -*Version: 1.0.0-RC2 (Optimus - RC2) +*Version: 1.0 (Optimus - Final) ------------------------------------------------------------------------------- @@ -13,7 +13,7 @@ Table of Content: I. Introduction II. Installation -III.Using JSONlab +III.Using JSONLab IV. Known Issues and TODOs V. Contribution and feedback @@ -43,19 +43,19 @@ general-purpose file specifications, such as [http://www.hdfgroup.org/HDF5/whatishdf5.html HDF5], with significantly reduced complexity and enhanced performance. -JSONlab is a free and open-source implementation of a JSON/UBJSON encoder +JSONLab is a free and open-source implementation of a JSON/UBJSON encoder and a decoder in the native MATLAB language. It can be used to convert a MATLAB data structure (array, struct, cell, struct array and cell array) into JSON/UBJSON formatted strings, or to decode a JSON/UBJSON file into MATLAB -data structure. JSONlab supports both MATLAB and +data structure. JSONLab supports both MATLAB and [http://www.gnu.org/software/octave/ GNU Octave] (a free MATLAB clone). ------------------------------------------------------------------------------- II. Installation -The installation of JSONlab is no different than any other simple -MATLAB toolbox. You only need to download/unzip the JSONlab package +The installation of JSONLab is no different than any other simple +MATLAB toolbox. You only need to download/unzip the JSONLab package to a folder, and add the folder's path to MATLAB/Octave's path list by using the following command: @@ -64,13 +64,13 @@ by using the following command: If you want to add this path permanently, you need to type "pathtool", browse to the jsonlab root folder and add to the list, then click "Save". Then, run "rehash" in MATLAB, and type "which loadjson", if you see an -output, that means JSONlab is installed for MATLAB/Octave. +output, that means JSONLab is installed for MATLAB/Octave. ------------------------------------------------------------------------------- -III.Using JSONlab +III.Using JSONLab -JSONlab provides two functions, loadjson.m -- a MATLAB->JSON decoder, +JSONLab provides two functions, loadjson.m -- a MATLAB->JSON decoder, and savejson.m -- a MATLAB->JSON encoder, for the text-based JSON, and two equivallent functions -- loadubjson and saveubjson for the binary JSON. The detailed help info for the four functions can be found below: @@ -84,14 +84,15 @@ JSON. The detailed help info for the four functions can be found below: parse a JSON (JavaScript Object Notation) file or string authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) - date: 2011/09/09 + created on 2011/09/09, including previous works from + Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713 - date: 2009/11/02 + created on 2009/11/02 Fran�ois Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393 - date: 2009/03/22 + created on 2009/03/22 Joel Feenstra: http://www.mathworks.com/matlabcentral/fileexchange/20565 - date: 2008/07/03 + created on 2008/07/03 $Id: loadjson.m 452 2014-11-22 16:43:33Z fangq $ @@ -99,13 +100,14 @@ JSON. The detailed help info for the four functions can be found below: fname: input file name, if fname contains "{}" or "[]", fname will be interpreted as a JSON string opt: a struct to store parsing options, opt can be replaced by - a list of ('param',value) pairs. opt can have the following + a list of ('param',value) pairs - the param string is equivallent + to a field in opt. opt can have the following fields (first in [.|.] is the default) - opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat + opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat for each element of the JSON data, and group arrays based on the cell2mat rules. - opt.FastArrayParser [1|0 or integer]: if set to 1, use a + opt.FastArrayParser [1|0 or integer]: if set to 1, use a speed-optimized array parser when loading an array object. The fast array parser may collapse block arrays into a single large @@ -119,11 +121,16 @@ JSON. The detailed help info for the four functions can be found below: arrays; setting to 3 will return to a 2D cell array of 1D vectors; setting to 4 will return a 3D cell array. - opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar. + opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar. output: dat: a cell array, where {...} blocks are converted into cell arrays, and [...] are converted to arrays + + examples: + dat=loadjson('{"obj":{"string":"value","array":[1,2,3]}}') + dat=loadjson(['examples' filesep 'example1.json']) + dat=loadjson(['examples' filesep 'example1.json'],'SimplifyCell',1) </pre> === savejson.m === @@ -138,15 +145,17 @@ JSON. The detailed help info for the four functions can be found below: Object Notation) string author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) - created on 2011/09/09 + created on 2011/09/09 - $Id: savejson.m 450 2014-11-18 20:53:31Z fangq $ + $Id: savejson.m 458 2014-12-19 22:17:17Z fangq $ input: - rootname: name of the root-object, if set to '', will use variable name - obj: a MATLAB object (array, cell, cell array, struct, struct array) - filename: a string for the file name to save the output JSON data - opt: a struct for additional options, use [] if all use default + rootname: the name of the root-object, when set to '', the root name + is ignored, however, when opt.ForceRootName is set to 1 (see below), + the MATLAB variable name will be used as the root name. + obj: a MATLAB object (array, cell, cell array, struct, struct array). + filename: a string for the file name to save the output JSON data. + opt: a struct for additional options, ignore to use default values. opt can have the following fields (first in [.|.] is the default) opt.FileName [''|string]: a file name to save the output JSON data @@ -184,7 +193,7 @@ JSON. The detailed help info for the four functions can be found below: opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern to represent NaN opt.JSONP [''|string]: to generate a JSONP output (JSON with padding), - for example, if opt.JSON='foo', the JSON data is + for example, if opt.JSONP='foo', the JSON data is wrapped inside a function call as 'foo(...);' opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson back to the string form @@ -197,11 +206,15 @@ JSON. The detailed help info for the four functions can be found below: json: a string in the JSON format (see http://json.org) examples: - a=struct('node',[1 9 10; 2 1 1.2], 'elem',[9 1;1 2;2 3],... - 'face',[9 01 2; 1 2 3; NaN,Inf,-Inf], 'author','FangQ'); - savejson('mesh',a) - savejson('',a,'ArrayIndent',0,'FloatFormat','\t%.5g') -</pre> + jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],... + 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],... + 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;... + 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],... + 'MeshCreator','FangQ','MeshTitle','T6 Cube',... + 'SpecialData',[nan, inf, -inf]); + savejson('jmesh',jsonmesh) + savejson('',jsonmesh,'ArrayIndent',0,'FloatFormat','\t%.5g') + </pre> === loadubjson.m === @@ -213,7 +226,7 @@ JSON. The detailed help info for the four functions can be found below: parse a JSON (JavaScript Object Notation) file or string authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) - date: 2013/08/01 + created on 2013/08/01 $Id: loadubjson.m 436 2014-08-05 20:51:40Z fangq $ @@ -221,12 +234,28 @@ JSON. The detailed help info for the four functions can be found below: fname: input file name, if fname contains "{}" or "[]", fname will be interpreted as a UBJSON string opt: a struct to store parsing options, opt can be replaced by - a list of ('param',value) pairs. The param string is equivallent - to a field in opt. + a list of ('param',value) pairs - the param string is equivallent + to a field in opt. opt can have the following + fields (first in [.|.] is the default) + + opt.SimplifyCell [0|1]: if set to 1, loadubjson will call cell2mat + for each element of the JSON data, and group + arrays based on the cell2mat rules. + opt.IntEndian [B|L]: specify the endianness of the integer fields + in the UBJSON input data. B - Big-Endian format for + integers (as required in the UBJSON specification); + L - input integer fields are in Little-Endian order. output: dat: a cell array, where {...} blocks are converted into cell arrays, and [...] are converted to arrays + + examples: + obj=struct('string','value','array',[1 2 3]); + ubjdata=saveubjson('obj',obj); + dat=loadubjson(ubjdata) + dat=loadubjson(['examples' filesep 'example1.ubj']) + dat=loadubjson(['examples' filesep 'example1.ubj'],'SimplifyCell',1) </pre> === saveubjson.m === @@ -241,15 +270,17 @@ JSON. The detailed help info for the four functions can be found below: Binary JSON (UBJSON) binary string author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) - created on 2013/08/17 + created on 2013/08/17 $Id: saveubjson.m 440 2014-09-17 19:59:45Z fangq $ input: - rootname: name of the root-object, if set to '', will use variable name + rootname: the name of the root-object, when set to '', the root name + is ignored, however, when opt.ForceRootName is set to 1 (see below), + the MATLAB variable name will be used as the root name. obj: a MATLAB object (array, cell, cell array, struct, struct array) - filename: a string for the file name to save the output JSON data - opt: a struct for additional options, use [] if all use default + filename: a string for the file name to save the output UBJSON data + opt: a struct for additional options, ignore to use default values. opt can have the following fields (first in [.|.] is the default) opt.FileName [''|string]: a file name to save the output JSON data @@ -281,37 +312,42 @@ JSON. The detailed help info for the four functions can be found below: wrapped inside a function call as 'foo(...);' opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson back to the string form + opt can be replaced by a list of ('param',value) pairs. The param - string is equivallent to a field in opt. + string is equivallent to a field in opt and is case sensitive. output: - json: a string in the JSON format (see http://json.org) + json: a binary string in the UBJSON format (see http://ubjson.org) examples: - a=struct('node',[1 9 10; 2 1 1.2], 'elem',[9 1;1 2;2 3],... - 'face',[9 01 2; 1 2 3; NaN,Inf,-Inf], 'author','FangQ'); - saveubjson('mesh',a) - saveubjson('mesh',a,'meshdata.ubj') + jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],... + 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],... + 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;... + 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],... + 'MeshCreator','FangQ','MeshTitle','T6 Cube',... + 'SpecialData',[nan, inf, -inf]); + saveubjson('jsonmesh',jsonmesh) + saveubjson('jsonmesh',jsonmesh,'meshdata.ubj') </pre> === examples === Under the "examples" folder, you can find several scripts to demonstrate the -basic utilities of JSONlab. Running the "demo_jsonlab_basic.m" script, you +basic utilities of JSONLab. Running the "demo_jsonlab_basic.m" script, you will see the conversions from MATLAB data structure to JSON text and backward. In "jsonlab_selftest.m", we load complex JSON files downloaded from the Internet and validate the loadjson/savejson functions for regression testing purposes. Similarly, a "demo_ubjson_basic.m" script is provided to test the saveubjson and loadubjson pairs for various matlab data structures. -Please run these examples and understand how JSONlab works before you use +Please run these examples and understand how JSONLab works before you use it to process your data. ------------------------------------------------------------------------------- IV. Known Issues and TODOs -JSONlab has several known limitations. We are striving to make it more general +JSONLab has several known limitations. We are striving to make it more general and robust. Hopefully in a few future releases, the limitations become less. Here are the known issues: @@ -325,31 +361,33 @@ in MATLAB to get consistant results # an unofficial N-D array count syntax is implemented in saveubjson. We are \ actively communicating with the UBJSON spec maintainer to investigate the \ possibility of making it upstream +# loadubjson can not parse all UBJSON Specification (Draft 9) compliant \ +files, however, it can parse all UBJSON files produced by saveubjson. ------------------------------------------------------------------------------- V. Contribution and feedback -JSONlab is an open-source project. This means you can not only use it and modify -it as you wish, but also you can contribute your changes back to JSONlab so +JSONLab is an open-source project. This means you can not only use it and modify +it as you wish, but also you can contribute your changes back to JSONLab so that everyone else can enjoy the improvement. For anyone who want to contribute, -please download JSONlab source code from it's subversion repository by using the +please download JSONLab source code from it's subversion repository by using the following command: svn checkout svn://svn.code.sf.net/p/iso2mesh/code/trunk/jsonlab jsonlab You can make changes to the files as needed. Once you are satisfied with your changes, and ready to share it with others, please cd the root directory of -JSONlab, and type +JSONLab, and type svn diff > yourname_featurename.patch -You then email the .patch file to JSONlab's maintainer, Qianqian Fang, at +You then email the .patch file to JSONLab's maintainer, Qianqian Fang, at the email address shown in the beginning of this file. Qianqian will review the changes and commit it to the subversion if they are satisfactory. We appreciate any suggestions and feedbacks from you. Please use iso2mesh's -mailing list to report any questions you may have with JSONlab: +mailing list to report any questions you may have with JSONLab: http://groups.google.com/group/iso2mesh-users?hl=en&pli=1 diff --git a/loadjson.m b/loadjson.m index bcf0751a06067ca62e1d7967c3ca587dafdda8b8..d70a4fc3a75cb8dc294684373c11ba4f6280007a 100644 --- a/loadjson.m +++ b/loadjson.m @@ -7,14 +7,15 @@ function data = loadjson(fname,varargin) % parse a JSON (JavaScript Object Notation) file or string % % authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) -% date: 2011/09/09 +% created on 2011/09/09, including previous works from +% % Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713 -% date: 2009/11/02 +% created on 2009/11/02 % François Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393 -% date: 2009/03/22 +% created on 2009/03/22 % Joel Feenstra: % http://www.mathworks.com/matlabcentral/fileexchange/20565 -% date: 2008/07/03 +% created on 2008/07/03 % % $Id$ % @@ -22,13 +23,14 @@ function data = loadjson(fname,varargin) % fname: input file name, if fname contains "{}" or "[]", fname % will be interpreted as a JSON string % opt: a struct to store parsing options, opt can be replaced by -% a list of ('param',value) pairs. opt can have the following +% a list of ('param',value) pairs - the param string is equivallent +% to a field in opt. opt can have the following % fields (first in [.|.] is the default) % -% opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat +% opt.SimplifyCell [0|1]: if set to 1, loadjson will call cell2mat % for each element of the JSON data, and group % arrays based on the cell2mat rules. -% opt.FastArrayParser [1|0 or integer]: if set to 1, use a +% opt.FastArrayParser [1|0 or integer]: if set to 1, use a % speed-optimized array parser when loading an % array object. The fast array parser may % collapse block arrays into a single large @@ -42,16 +44,21 @@ function data = loadjson(fname,varargin) % arrays; setting to 3 will return to a 2D cell % array of 1D vectors; setting to 4 will return a % 3D cell array. -% opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar. +% opt.ShowProgress [0|1]: if set to 1, loadjson displays a progress bar. % % output: % dat: a cell array, where {...} blocks are converted into cell arrays, % and [...] are converted to arrays % +% examples: +% dat=loadjson('{"obj":{"string":"value","array":[1,2,3]}}') +% dat=loadjson(['examples' filesep 'example1.json']) +% dat=loadjson(['examples' filesep 'example1.json'],'SimplifyCell',1) +% % license: % BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details % -% -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) +% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) % global pos inStr len esc index_esc len_esc isoct arraytoken diff --git a/loadubjson.m b/loadubjson.m index d1fa6e1a167527790454276fedef76fdd6ef5d58..9ee198301881f816971fa393f1939dd70d4e950c 100644 --- a/loadubjson.m +++ b/loadubjson.m @@ -7,7 +7,7 @@ function data = loadubjson(fname,varargin) % parse a JSON (JavaScript Object Notation) file or string % % authors:Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) -% date: 2013/08/01 +% created on 2013/08/01 % % $Id$ % @@ -15,17 +15,33 @@ function data = loadubjson(fname,varargin) % fname: input file name, if fname contains "{}" or "[]", fname % will be interpreted as a UBJSON string % opt: a struct to store parsing options, opt can be replaced by -% a list of ('param',value) pairs. The param string is equivallent -% to a field in opt. +% a list of ('param',value) pairs - the param string is equivallent +% to a field in opt. opt can have the following +% fields (first in [.|.] is the default) +% +% opt.SimplifyCell [0|1]: if set to 1, loadubjson will call cell2mat +% for each element of the JSON data, and group +% arrays based on the cell2mat rules. +% opt.IntEndian [B|L]: specify the endianness of the integer fields +% in the UBJSON input data. B - Big-Endian format for +% integers (as required in the UBJSON specification); +% L - input integer fields are in Little-Endian order. % % output: % dat: a cell array, where {...} blocks are converted into cell arrays, % and [...] are converted to arrays % +% examples: +% obj=struct('string','value','array',[1 2 3]); +% ubjdata=saveubjson('obj',obj); +% dat=loadubjson(ubjdata) +% dat=loadubjson(['examples' filesep 'example1.ubj']) +% dat=loadubjson(['examples' filesep 'example1.ubj'],'SimplifyCell',1) +% % license: % BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details % -% -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) +% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) % global pos inStr len esc index_esc len_esc isoct arraytoken fileendian systemendian diff --git a/savejson.m b/savejson.m index 90c5bd1d059aa8689683aa80d238a8610810d96b..e739eb769f419b5976c022505bb580d0c3e316be 100644 --- a/savejson.m +++ b/savejson.m @@ -9,15 +9,17 @@ function json=savejson(rootname,obj,varargin) % Object Notation) string % % author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) -% created on 2011/09/09 +% created on 2011/09/09 % % $Id$ % % input: -% rootname: name of the root-object, if set to '', will use variable name -% obj: a MATLAB object (array, cell, cell array, struct, struct array) -% filename: a string for the file name to save the output JSON data -% opt: a struct for additional options, use [] if all use default +% rootname: the name of the root-object, when set to '', the root name +% is ignored, however, when opt.ForceRootName is set to 1 (see below), +% the MATLAB variable name will be used as the root name. +% obj: a MATLAB object (array, cell, cell array, struct, struct array). +% filename: a string for the file name to save the output JSON data. +% opt: a struct for additional options, ignore to use default values. % opt can have the following fields (first in [.|.] is the default) % % opt.FileName [''|string]: a file name to save the output JSON data @@ -55,7 +57,7 @@ function json=savejson(rootname,obj,varargin) % opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern % to represent NaN % opt.JSONP [''|string]: to generate a JSONP output (JSON with padding), -% for example, if opt.JSON='foo', the JSON data is +% for example, if opt.JSONP='foo', the JSON data is % wrapped inside a function call as 'foo(...);' % opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson % back to the string form @@ -68,15 +70,19 @@ function json=savejson(rootname,obj,varargin) % json: a string in the JSON format (see http://json.org) % % examples: -% a=struct('node',[1 9 10; 2 1 1.2], 'elem',[9 1;1 2;2 3],... -% 'face',[9 01 2; 1 2 3; NaN,Inf,-Inf], 'author','FangQ'); -% savejson('mesh',a) -% savejson('',a,'ArrayIndent',0,'FloatFormat','\t%.5g') +% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],... +% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],... +% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;... +% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],... +% 'MeshCreator','FangQ','MeshTitle','T6 Cube',... +% 'SpecialData',[nan, inf, -inf]); +% savejson('jmesh',jsonmesh) +% savejson('',jsonmesh,'ArrayIndent',0,'FloatFormat','\t%.5g') % % license: % BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details % -% -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) +% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) % if(nargin==1) diff --git a/saveubjson.m b/saveubjson.m index 395c139c32a38035977226c9e1a89e449395a201..6cd99ea46baff4b77cf68cd1b78ad1d8f59edf17 100644 --- a/saveubjson.m +++ b/saveubjson.m @@ -9,15 +9,17 @@ function json=saveubjson(rootname,obj,varargin) % Binary JSON (UBJSON) binary string % % author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu) -% created on 2013/08/17 +% created on 2013/08/17 % % $Id$ % % input: -% rootname: name of the root-object, if set to '', will use variable name +% rootname: the name of the root-object, when set to '', the root name +% is ignored, however, when opt.ForceRootName is set to 1 (see below), +% the MATLAB variable name will be used as the root name. % obj: a MATLAB object (array, cell, cell array, struct, struct array) -% filename: a string for the file name to save the output JSON data -% opt: a struct for additional options, use [] if all use default +% filename: a string for the file name to save the output UBJSON data +% opt: a struct for additional options, ignore to use default values. % opt can have the following fields (first in [.|.] is the default) % % opt.FileName [''|string]: a file name to save the output JSON data @@ -49,21 +51,26 @@ function json=saveubjson(rootname,obj,varargin) % wrapped inside a function call as 'foo(...);' % opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson % back to the string form +% % opt can be replaced by a list of ('param',value) pairs. The param -% string is equivallent to a field in opt. +% string is equivallent to a field in opt and is case sensitive. % output: -% json: a string in the JSON format (see http://json.org) +% json: a binary string in the UBJSON format (see http://ubjson.org) % % examples: -% a=struct('node',[1 9 10; 2 1 1.2], 'elem',[9 1;1 2;2 3],... -% 'face',[9 01 2; 1 2 3; NaN,Inf,-Inf], 'author','FangQ'); -% saveubjson('mesh',a) -% saveubjson('mesh',a,'meshdata.ubj') +% jsonmesh=struct('MeshNode',[0 0 0;1 0 0;0 1 0;1 1 0;0 0 1;1 0 1;0 1 1;1 1 1],... +% 'MeshTetra',[1 2 4 8;1 3 4 8;1 2 6 8;1 5 6 8;1 5 7 8;1 3 7 8],... +% 'MeshTri',[1 2 4;1 2 6;1 3 4;1 3 7;1 5 6;1 5 7;... +% 2 8 4;2 8 6;3 8 4;3 8 7;5 8 6;5 8 7],... +% 'MeshCreator','FangQ','MeshTitle','T6 Cube',... +% 'SpecialData',[nan, inf, -inf]); +% saveubjson('jsonmesh',jsonmesh) +% saveubjson('jsonmesh',jsonmesh,'meshdata.ubj') % % license: % BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details % -% -- this function is part of jsonlab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) +% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab) % if(nargin==1)