JSON: Difference between revisions

455 bytes added ,  13 years ago
Added a Clojure example.
(→‎{{header|Python}}: Add some output)
(Added a Clojure example.)
Line 2:
Load a [[wp:JSON|JSON]] string into a data structure. Also create a new data structure and serialize it into JSON.
Use objects and arrays (as appropriate for your language) and make sure your JSON is valid (http://www.jsonlint.com/).
 
=={{header|Clojure}}==
<lang clojure>(ns json.example
(:use [clojure.contrib.json]))
 
; Load as Clojure data structures and bind the resulting structure to 'json-map'.
(def json-map (read-json "{ \"foo\": 1, \"bar\": [10, \"apples\"] }"))
 
; Use pr-str to print out the Clojure representation of the JSON created by read-json.
(pr-str json-map)
 
; Pretty-print the Clojure representation of JSON. We've come full circle.
(pprint-json json-map)</lang>
 
=={{header|Go}}==
72

edits