diff --git a/src/jzon.lisp b/src/jzon.lisp index 0b9f0ed..3a0c5f6 100644 --- a/src/jzon.lisp +++ b/src/jzon.lisp @@ -1208,9 +1208,10 @@ see `end-array'" (error 'json-error :format-control "The writer has been closed.")) (with-slots (%stream %stack %depth %max-depth) writer (case (car %stack) - ((:array-value) (progn - (write-char #\, %stream) - (%write-indentation writer))) + ((:array) (progn (%write-indentation writer) + (setf (car %stack) :array-value))) + ((:array-value) (progn (write-char #\, %stream) + (%write-indentation writer))) ((:object-key) (setf (car %stack) :object-value)) ((:object :object-value) (error "Expecting object key")) ((:complete) (error "Attempting to write array when value already written to writer"))) @@ -1230,7 +1231,7 @@ see `end-array'" (let ((context (car %stack))) (case context ((:array :array-value)) - (t (error "Attempting to close array while in ~A" context))) + (t (error "Attempting to close array while in ~A" context))) (pop %stack) (decf %depth) (when (eq context :array-value) diff --git a/test/jzon-tests.lisp b/test/jzon-tests.lisp index f509e51..4b66fdb 100644 --- a/test/jzon-tests.lisp +++ b/test/jzon-tests.lisp @@ -749,6 +749,21 @@ (is (string= "[]" (jzon:stringify #()))) (is (string= "[42,\"hello\",[]]" (jzon:stringify #(42 "hello" #()))))) +(test stringify-nested-array + (is (string= "[[1,2],[3,4]]" (jzon:stringify #(#(1 2) #(3 4)))))) + +(test stringify-nested-array-pretty + (is (string= "[ + [ + 1, + 2 + ], + [ + 3, + 4 + ] +]" (jzon:stringify #(#(1 2) #(3 4)) :pretty t)))) + (defun recode (value) "Shorthand for (jzon:parse (jzon:stringify value))" (jzon:parse (jzon:stringify value)))