7

In JavaScript one can turn a js data structure into a JSON string via

JSON.stringify({somedata: { somesubdata: {}}})

And somewhere else, one can parse it again into a JS data structure via

var my_obj = JSON.parse("{"somedata":{"some_subdata":{}}}");

What would be the equivalent in Clojure/ClojureScript for the edn format?

I want to stringify some data on a ClojureScript front-end and parse it on a Clojure back-end. (and vice versa)

Anton Harald
  • 5,772
  • 4
  • 27
  • 61
  • 3
    Possible duplicate of [Clojure & ClojureScript: clojure.core/read-string, clojure.edn/read-string and cljs.reader/read-string](http://stackoverflow.com/questions/24661655/clojure-clojurescript-clojure-core-read-string-clojure-edn-read-string-and-c) – Piotrek Bzdyl Mar 24 '16 at 19:38
  • I don't think that's a duplicate of this question, though an answer to this question is contained in part of the first answer – Arthur Ulfeldt Mar 24 '16 at 20:49

1 Answers1

9

As pointed out in a comment, a very detailed answer to this question can be found at the referenced link above.

After reading this, a quick answer, maybe especailly for people coming from JavaScript, would be:

in Clojure:

parse: clojure.edn/read-string
stringify: prn-str

in ClojureScript:

parse: cljs.reader/read-string
stringify: prn-str
Anton Harald
  • 5,772
  • 4
  • 27
  • 61