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

InputStream question #59

Open archaic opened 3 years ago

archaic commented 3 years ago

Hello, I am looking to migrate from clojure.data.json to jsonista, but am unsure how to process an input stream of JSON encoded maps. Note I can't preprocess the input stream to be a vector of maps either.

In clojure.data.json I do this:

(loop [data []]
    (if-let [datom 
             (try (json/read reader)
                  (catch java.io.EOFException _)
                  (catch Exception Ex
                    (log/error Ex)))]
      (recur (conj data
                   datom))
      data))
FieryCod commented 2 years ago

@archaic InputStream should be supported out of the box by ReadValue protocol.

Try using json/read-value.

archaic commented 2 years ago

Hello, after using ReadValue on either an InputStream or Reader, it works on the first value, the second value results in a StreamClosed exception. If I get time I will dig deeper, but its not a high priority as clojure.data.json is working for me.