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

0 votes
in ClojureScript by


(def foo (let [bar "baz"]
           (reify Object)))
(.stringify js/JSON (clj->js foo))

Or oneliner:

clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version
"1.10.520"}}}' -m cljs.main -re node -e '(def foo (let [bar "baz"]
(reify Object))) (.stringify js/JSON (clj->js foo))'


There's bar var value printed which is surprising and may be dangerous if it exposes sensitive data in case of mistake:



No bar in the output.

1 Answer

0 votes
selected by
Best answer

You need to implement toJSON method
(let [bar "baz"]
(reify Object

(toJSON [this]
   (js/JSON.stringify #js{:bar bar})))))


This structure printed is just a implementation detail.