saveubjson.m

  json=saveubjson(rootname,obj,filename)
     or
  json=saveubjson(rootname,obj,opt)
  json=saveubjson(rootname,obj,'param1',value1,'param2',value2,...)

  convert a MATLAB object (cell, struct or array) into a Universal 
  Binary JSON (UBJSON) binary string

  author: Qianqian Fang (fangq<at> nmr.mgh.harvard.edu)
  created on 2013/08/17

  $Id: saveubjson.m 460 2015-01-03 00:30:45Z fangq $

  input:
       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 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
         opt.ArrayToStruct[0|1]: when set to 0, saveubjson outputs 1D/2D
                          array in JSON array format; if sets to 1, an
                          array will be shown as a struct with fields
                          "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
                          sparse arrays, the non-zero elements will be
                          saved to _ArrayData_ field in triplet-format i.e.
                          (ix,iy,val) and "_ArrayIsSparse_" will be added
                          with a value of 1; for a complex array, the 
                          _ArrayData_ array will include two columns 
                          (4 for sparse) to record the real and imaginary 
                          parts, and also "_ArrayIsComplex_":1 is added. 
         opt.ParseLogical [1|0]: if this is set to 1, logical array elem
                          will use true/false rather than 1/0.
         opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
                          numerical element will be shown without a square
                          bracket, unless it is the root object; if 0, square
                          brackets are forced for any numerical arrays.
         opt.ForceRootName [0|1]: when set to 1 and rootname is empty, saveubjson
                          will use the name of the passed obj variable as the 
                          root object name; if obj is an expression and 
                          does not have a name, 'root' will be used; if this 
                          is set to 0 and rootname is empty, the root level 
                          will be merged down to the lower level.
         opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
                          for example, if opt.JSON='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

         opt can be replaced by a list of ('param',value) pairs. The param 
         string is equivallent to a field in opt and is case sensitive.
  output:
       json: a binary string in the UBJSON format (see http://ubjson.org)

  examples:
       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)
Powered by Habitat