From 3f8187b2dfab504f201c129b55d7b871c973c0e1 Mon Sep 17 00:00:00 2001
From: fangq <fangq@786e58fb-9377-0410-9ff7-e4ac0ac0635c>
Date: Mon, 7 Oct 2013 16:38:31 +0000
Subject: [PATCH] apply patches from Yul Kang, better handling of empty arrays
 and structs

git-svn-id: http://svn.code.sf.net/p/iso2mesh/code/trunk/jsonlab@415 786e58fb-9377-0410-9ff7-e4ac0ac0635c
---
 AUTHORS.txt   | 5 +++++
 ChangeLog.txt | 4 ++++
 README.txt    | 2 +-
 loadjson.m    | 7 +++++++
 loadubjson.m  | 7 +++++++
 savejson.m    | 4 ++--
 6 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/AUTHORS.txt b/AUTHORS.txt
index 80446a8..9dd3fc7 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -34,3 +34,8 @@ This toolbox contains patches submitted by the following contributors:
   - loadjson crashes for sparse complex column vector.
   - Data is corrupted by savejson for sparse real row vector.
   - savejson crashes for sparse complex row vector. 
+
+- Yul Kang <yul.kang.on at gmail.com>
+  patches for svn revision 415.
+  - savejson saves an empty cell array as [] instead of null
+  - loadjson differentiates an empty struct from an empty array
diff --git a/ChangeLog.txt b/ChangeLog.txt
index f409e76..62be044 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -6,6 +6,10 @@
 
 JSONlab ChangeLog (key features marked by *):
 
+== JSONlab 0.9.8-1 (codename: Optimus - alpha update 1), FangQ <fangq (at) nmr.mgh.harvard.edu> ==
+
+ 2013/10/07 Better round-trip conservation for empty arrays and structs (patch submitted by Yul Kang)
+
 == JSONlab 0.9.8 (codename: Optimus - alpha), FangQ <fangq (at) nmr.mgh.harvard.edu> ==
  2013/08/23 *Universal Binary JSON (UBJSON) support, including both saveubjson and loadubjson
 
diff --git a/README.txt b/README.txt
index 83616b8..f77dd05 100644
--- a/README.txt
+++ b/README.txt
@@ -315,7 +315,7 @@ 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
 following command:
 
- svn co https://iso2mesh.svn.sourceforge.net/svnroot/iso2mesh/trunk/jsonlab jsonlab
+ 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 
diff --git a/loadjson.m b/loadjson.m
index 2dfcd27..32d40ef 100644
--- a/loadjson.m
+++ b/loadjson.m
@@ -398,6 +398,13 @@ function val = parse_value(varargin)
             return;
         case '{'
             val = parse_object(varargin{:});
+            if isstruct(val)
+                if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
+                    val=jstruct2array(val);
+                end
+            elseif isempty(val)
+                val = struct;
+            end
             return;
         case {'-','0','1','2','3','4','5','6','7','8','9'}
             val = parse_number(varargin{:});
diff --git a/loadubjson.m b/loadubjson.m
index 10ee2b4..b92384b 100644
--- a/loadubjson.m
+++ b/loadubjson.m
@@ -376,6 +376,13 @@ function val = parse_value(varargin)
             return;
         case '{'
             val = parse_object(varargin{:});
+            if isstruct(val)
+                if(~isempty(strmatch('x0x5F_ArrayType_',fieldnames(val), 'exact')))
+                    val=jstruct2array(val);
+                end
+            elseif isempty(val)
+                val = struct;
+            end
             return;
         case {'i','U','I','l','L','d','D'}
             val = parse_number(varargin{:});
diff --git a/savejson.m b/savejson.m
index 3163272..9c7fe86 100644
--- a/savejson.m
+++ b/savejson.m
@@ -157,9 +157,9 @@ if(len>1)
     end
 elseif(len==0)
     if(~isempty(name))
-        txt=sprintf('%s"%s": null',padding0, checkname(name,varargin{:})); name=''; 
+        txt=sprintf('%s"%s": []',padding0, checkname(name,varargin{:})); name=''; 
     else
-        txt=sprintf('%snull',padding0); 
+        txt=sprintf('%s[]',padding0); 
     end
 end
 for i=1:len
-- 
GitLab