metosin / jsonista

Clojure library for fast JSON encoding and decoding.
https://cljdoc.org/d/metosin/jsonista
Eclipse Public License 2.0
422 stars 30 forks source link

Lazy keys are not forced #30

Open studer-l opened 4 years ago

studer-l commented 4 years ago

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\"]]"
miikka commented 3 years ago

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

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