jsonista icon indicating copy to clipboard operation
jsonista copied to clipboard

Lazy keys are not forced

Open studer-l opened this issue 4 years ago • 1 comments

Given a hashmap with lazy-seq keys, jsonista does not force their evaluation.

In all other cases that I came up with, lazy-seqs are forced (values in hashmaps, other containers, nested), hence I assume that this is a bug.

See the following repl session:

jsonista.core-test> (j/write-value-as-string {(lazy-seq '(:key)) :value}) ;; bug
"{\"clojure.lang.LazySeq@3cd66127\":\"value\"}"
jsonista.core-test> (j/write-value-as-string {:key (lazy-seq '(:value))}) ;; correct
"{\"key\":[\"value\"]}"
jsonista.core-test> (j/write-value-as-string (lazy-seq (list (lazy-seq '(:one))))) ;; correct
"[[\"one\"]]"
jsonista.core-test> (j/write-value-as-string [(lazy-seq '(:one)) (lazy-seq '(:two))]) ;; correct
"[[\"one\"],[\"two\"]]"

studer-l avatar Apr 06 '20 21:04 studer-l

JSON object keys are strings, so the correct result would be like this:

user=> (j/write-value-as-string {'(:key) :value})
"{\"(:key)\":\"value\"}"

miikka avatar Jan 29 '21 09:01 miikka