Share your thoughts in the 2020 Clojure Community Survey!

Welcome! Please see the About page for a little more info on how this works.

+1 vote
in IO by

I need to read json line input in stdin

Example INPUT

{ "foo" : "bar" }

{ "foo" : "bar" }

2 Answers

+2 votes
selected by
Best answer
  1. Use (read-line) to read single line from *in*
  2. Use any json parser to parse this string.

Example using jsonista:

$ clj -Sdeps '{:deps {metosin/jsonista {:mvn/version "0.2.4"}}}'
Clojure 1.10.0
user=> (require '[jsonista.core :as j])
user=> (j/read-value (read-line))
{"foo": "bar"}
{"foo" "bar"}
Thanks for your answer,
I'll test this and return
+1 vote

It depends which library you are using. I've done this in jet using cheshire: