Looks like the example JSON functions choke on empty objects. I made a
quick and dirty fix, but I'm not sure if I introduced extra bugs.

Diff follows:
######################################################################
--- json.orig.l 2012-01-27 07:34:25.000000000 -0300
+++ json.l      2012-01-27 07:46:32.000000000 -0300
@@ -6,7 +6,7 @@
    (case (read "_")
       ("{"
          (make
-            (for (X (readJson)  T  (readJson))
+            (for (X (readJson) (not (= "}" X)) (readJson))
                (checkJson ":" (readJson))
                (link (cons X (readJson)))
                (T (= "}" (setq X (readJson))))
@@ -14,7 +14,7 @@
       ("["
          (make
             (link T)  # Array marker
-            (for (X (readJson)  T  (readJson))
+            (for (X (readJson) (not (= "]" X)) (readJson))
                (link X)
                (T (= "]" (setq X (readJson))))
                (checkJson "," X) ) ) )
@@ -22,7 +22,7 @@
  
 (de printJson (Item)  # For simplicity, without indentation
    (cond
-      ((atom Item) (print Item))
+      ((atom Item) (if Item (print @) (prin "{}")))
       ((=T (car Item))
          (prin "[")
          (map
######################################################################

Tested with this:
: (pipe (prinl "{\"one\":[[],[1,2,3],[],[]],\"two\":{}}") (readJson)) 
-> (("one" T (T) (T 1 2 3) (T) (T)) ("two"))
: (printJson @)                                                      
{"one": [[], [1, 2, 3], [], []], "two": {}}-> "}"

If it's OK I'll edit the task page, buggy code is ugly code!

Cheers,
-José
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to