Skip to content

Commit

Permalink
Fix pretty printer on nested arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Zulu-Inuoe committed Feb 14, 2023
1 parent 6d57414 commit b25ca02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/jzon.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions test/jzon-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit b25ca02

Please sign in to comment.