Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 231 lines (161 sloc) 7.844 kb
02f0bd2a » stuartsierra
2012-10-12 README: reformat headings for GitHub, rearrange a few examples
1 data.json
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
2 ========================================
3
4 JSON parser/generator to/from Clojure data structures.
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
5
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
6 Follows the specification on http://json.org/
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
7
8
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
9
10 Releases and Dependency Information
02f0bd2a » stuartsierra
2012-10-12 README: reformat headings for GitHub, rearrange a few examples
11 ----------------------------------------
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
12
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
13 Latest stable release is [0.2.5]
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
14
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
15 [Leiningen] dependency information:
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
16
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
17 [org.clojure/data.json "0.2.5"]
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
18
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
19 [Maven] dependency information:
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
20
21 <dependency>
22 <groupId>org.clojure</groupId>
23 <artifactId>data.json</artifactId>
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
24 <version>0.2.5</version>
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
25 </dependency>
26
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
27 [Gradle] dependency information:
28
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
29 compile "org.clojure:data.json:0.2.5"
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
30
31 [Leiningen]: http://leiningen.org/
32 [Maven]: http://maven.apache.org/
33 [Gradle]: http://www.gradle.org/
34
35
02f0bd2a » stuartsierra
2012-10-12 README: reformat headings for GitHub, rearrange a few examples
36 Other versions:
37
38 * [All Released Versions](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22data.json%22)
39
40 * [Development Snapshots](https://oss.sonatype.org/index.html#nexus-search;gav~org.clojure~data.json~~~)
41
42 * [Development Snapshot Repositories](http://dev.clojure.org/display/doc/Maven+Settings+and+Repositories)
43
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
44
45
cf05fc96 » stuartsierra
2012-09-14 Remove old usage instructions from README
46 Usage
02f0bd2a » stuartsierra
2012-10-12 README: reformat headings for GitHub, rearrange a few examples
47 ----------------------------------------
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
48
cdd59a8a » stuartsierra
2012-08-09 Update README with latest release info & link to API docs
49 [API Documentation](http://clojure.github.com/data.json/)
50
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
51 Example usage:
1bedeb25 » stuartsierra
2012-10-05 README: Add example usage, update for 0.2.0 release
52
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
53 (ns example
54 (:require [clojure.data.json :as json])
1bedeb25 » stuartsierra
2012-10-05 README: Add example usage, update for 0.2.0 release
55
56 To convert to/from JSON strings, use `json/write-str` and `json/read-str`:
57
58 (json/write-str {:a 1 :b 2})
59 ;;=> "{\"a\":1,\"b\":2}"
60
61 (json/read-str "{\"a\":1,\"b\":2}")
62 ;;=> {"a" 1, "b" 2}
63
64 Note that these operations are not symmetric: converting Clojure data
65 into JSON is lossy.
66
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
67
68 ### Converting Key/Value Types
69
1bedeb25 » stuartsierra
2012-10-05 README: Add example usage, update for 0.2.0 release
70 You can specify a `:key-fn` to convert map keys on the way in or out:
71
72 (json/read-str "{\"a\":1,\"b\":2}"
73 :key-fn keyword)
74 ;;=> {:a 1, :b 2}
75
02f0bd2a » stuartsierra
2012-10-12 README: reformat headings for GitHub, rearrange a few examples
76 (json/write-str {:a 1 :b 2}
77 :key-fn #(.toUpperCase %))
78 ;;=> "{\"A\":1,\"B\":2}"
79
1bedeb25 » stuartsierra
2012-10-05 README: Add example usage, update for 0.2.0 release
80 (json/read-str "{\"a\":1,\"b\":2}"
81 :key-fn #(keyword "com.example" %))
82 ;;=> {:com.example/a 1, :com.example/b 2}
83
84 You can specify a `:value-fn` to convert map values on the way in or
85 out. The value-fn will be called with two arguments, the key and the
86 value, and it returns the updated value.
87
88 (defn my-value-reader [key value]
89 (if (= key :date)
90 (java.sql.Date/valueOf value)
91 value))
92
93 (json/read-str "{\"number\":42,\"date\":\"2012-06-02\"}"
94 :value-fn my-value-reader
95 :key-fn keyword)
96 ;;=> {:number 42, :date #inst "2012-06-02T04:00:00.000-00:00"}
97
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
98 Be aware that `:value-fn` only works on maps (JSON objects). If your
99 root data structure is, for example, a vector of dates, you will need
100 to pre- or post-process it outside of data.json. [clojure.walk] may be
101 useful for this.
102
103 [clojure.walk]: http://clojure.github.io/clojure/clojure.walk-api.html
104
105
106 ### Order of key-fn / value-fn
107
108 If you specify both a `:key-fn` and a `:value-fn` when **reading**,
109 the value-fn is called **after** the key has been processed by the
110 key-fn.
111
112 The **reverse** is true when **writing**:
1bedeb25 » stuartsierra
2012-10-05 README: Add example usage, update for 0.2.0 release
113
114 (defn my-value-writer [key value]
115 (if (= key :date)
116 (str (java.sql.Date. (.getTime value)))
117 value))
118
119 (json/write-str {:number 42, :date (java.util.Date. 112 5 2)}
120 :value-fn my-value-writer
121 :key-fn name)
122 ;;=> "{\"number\":42,\"date\":\"2012-06-02\"}"
123
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
124
125 ### Reading/Writing a Stream
126
eb829e6d » stuartsierra
2012-10-05 README: Fix sentences around read/write
127 You can also read JSON directly from a java.io.Reader with `json/read`
128 and write JSON directly to a java.io.Writer with `json/write`.
1bedeb25 » stuartsierra
2012-10-05 README: Add example usage, update for 0.2.0 release
129
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
130
131 ### More
132
133 Other options are available. Refer to the [API Documentation] for details.
134
135 [API Documentation]: http://clojure.github.com/data.json/
1bedeb25 » stuartsierra
2012-10-05 README: Add example usage, update for 0.2.0 release
136
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
137
138
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
139 Developer Information
02f0bd2a » stuartsierra
2012-10-12 README: reformat headings for GitHub, rearrange a few examples
140 ----------------------------------------
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
141
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
142 * [GitHub project](https://github.com/clojure/data.json)
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
143
02f1d609 » stuartsierra
2014-01-10 README: add link 'how to contribute'
144 * [How to contribute](http://dev.clojure.org/display/community/Contributing)
145
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
146 * [Bug Tracker](http://dev.clojure.org/jira/browse/DJSON)
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
147
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
148 * [Continuous Integration](http://build.clojure.org/job/data.json/)
149
150 * [Compatibility Test Matrix](http://build.clojure.org/job/data.json-test-matrix/)
9eb6de0a » stuartsierra
2011-03-18 Initial commit; new project adapted from clojure.contrib.json
151
d074ca52 » stuartsierra
2011-07-01 Update README with latest release number and changes log
152
153
154 Change Log
02f0bd2a » stuartsierra
2012-10-12 README: reformat headings for GitHub, rearrange a few examples
155 ----------------------------------------
d074ca52 » stuartsierra
2011-07-01 Update README with latest release number and changes log
156
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
157 * Development version 0.2.6-SNAPSHOT (current Git `master`)
158 * Release [0.2.5] on 2014-Jun-13
7d2a7dc8 » stuartsierra
2014-06-06 README: add DJSON-17 to change log
159 * Fix [DJSON-17]: throw exception on Infinite or NaN floating-point
160 values. Old behavior could produce invalid JSON.
6367d933 » stuartsierra
2014-01-10 Update README for 0.2.4 release
161 * Release [0.2.4] on 2014-Jan-10
867d0050 » stuartsierra
2014-01-10 DJSON-13: newline & flush output after pprint
162 * Small change in behavior: `clojure.data.json/pprint` now adds a
163 newline after its output just like `clojure.core/pprint`
164 * Fix [DJSON-13]: flush output after pprint
dfc54470 » stuartsierra
2014-01-10 README: fix capitalization
165 * Fix [DJSON-14]: handle EOF inside character escape
867d0050 » stuartsierra
2014-01-10 DJSON-13: newline & flush output after pprint
166 * Fix [DJSON-15]: bad syntax in test
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
167 * Release [0.2.3] on 2013-Aug-30
2f5364ac » stuartsierra
2014-01-10 README: Update change log
168 * Enhancement [DJSON-9]: option to escape U+2028 and U+2029
169 * Fix [DJSON-11]: printing unnecessary commas with value-fn
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
170 * Release [0.2.2] on 2013-Apr-07
2f5364ac » stuartsierra
2014-01-10 README: Update change log
171 * Fix [DJSON-7]: extra commas when removing key/value pairs)
172 * Fix [DJSON-8]: wrong output stream in `write-json`
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
173 * Release [0.2.1] on 2012-Oct-26
9ee90e2d » stuartsierra
2013-01-26 Document 0.2.1 release in README
174 * Restores backwards-compatibility with 0.1.x releases. The older
175 0.1.x APIs are marked as deprecated in their documentation. They
176 will be removed in a future release.
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
177 * Release [0.2.0] on 2012-Oct-12
9ee90e2d » stuartsierra
2013-01-26 Document 0.2.1 release in README
178 * **Not recommended for use**: this release introduced breaking API
179 changes (renaming core functions) without any path for
180 backwards-compatibility. Applications with transitive dependencies
181 on both the 0.2.x and 0.1.x APIs cannot use this version.
e49e341a » stuartsierra
2012-09-14 Add Release 0.2.0 (in development) change log to README
182 * New :key-fn and :value-fn permit flexible transformation
183 of values when reading & writing JSON
184 * Support for reading large integers as BigInt
185 * Optional support for reading decimals as BigDecimal
186 * Performance improvements
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
187 * Release [0.1.3] on 2012-Mar-09
cdd59a8a » stuartsierra
2012-08-09 Update README with latest release info & link to API docs
188 * Fix writing strings containing characters outside the BMP
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
189 * Release [0.1.2] on 2011-Oct-14
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
190 * Better parsing of hexadecimal character escapes
191 * Fix EOF-handling bug
2f5364ac » stuartsierra
2014-01-10 README: Update change log
192 * Fix [DJSON-1]: reflection warnings
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
193 * Release [0.1.1] on 2011-Jul-01
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
194 * Ensure that printing to `*out*` always uses a PrintWriter.
71244311 » stuartsierra
2014-01-10 README: add Gradle info and links to release tags
195 * Release [0.1.0] on 2011-Mar-18
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
196 * Initial release.
197 * Source-compatible with clojure.contrib.json, except for the name change.
198
7d2a7dc8 » stuartsierra
2014-06-06 README: add DJSON-17 to change log
199 [DJSON-17]: http://dev.clojure.org/jira/browse/DJSON-17
2f5364ac » stuartsierra
2014-01-10 README: Update change log
200 [DJSON-15]: http://dev.clojure.org/jira/browse/DJSON-15
ef676938 » stuartsierra
2014-01-10 README: add missing links to JIRA tickets
201 [DJSON-14]: http://dev.clojure.org/jira/browse/DJSON-14
202 [DJSON-13]: http://dev.clojure.org/jira/browse/DJSON-13
2f5364ac » stuartsierra
2014-01-10 README: Update change log
203 [DJSON-11]: http://dev.clojure.org/jira/browse/DJSON-11
204 [DJSON-9]: http://dev.clojure.org/jira/browse/DJSON-9
205 [DJSON-8]: http://dev.clojure.org/jira/browse/DJSON-8
206 [DJSON-7]: http://dev.clojure.org/jira/browse/DJSON-7
207 [DJSON-1]: http://dev.clojure.org/jira/browse/DJSON-1
208
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
209 [0.2.5]: https://github.com/clojure/data.json/tree/data.json-0.2.5
a4d3b74a » stuartsierra
2014-01-10 README: fix Markdown link syntax for release tags
210 [0.2.4]: https://github.com/clojure/data.json/tree/data.json-0.2.4
211 [0.2.3]: https://github.com/clojure/data.json/tree/data.json-0.2.3
212 [0.2.2]: https://github.com/clojure/data.json/tree/data.json-0.2.2
213 [0.2.1]: https://github.com/clojure/data.json/tree/data.json-0.2.1
214 [0.2.0]: https://github.com/clojure/data.json/tree/data.json-0.2.0
215 [0.1.3]: https://github.com/clojure/data.json/tree/data.json-0.1.3
216 [0.1.2]: https://github.com/clojure/data.json/tree/data.json-0.1.2
217 [0.1.1]: https://github.com/clojure/data.json/tree/data.json-0.1.1
218 [0.1.0]: https://github.com/clojure/data.json/tree/data.json-0.1.0
d074ca52 » stuartsierra
2011-07-01 Update README with latest release number and changes log
219
220
e6a8946e » stuartsierra
2014-06-13 Update README for 0.2.5 release
221
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
222 Copyright and License
02f0bd2a » stuartsierra
2012-10-12 README: reformat headings for GitHub, rearrange a few examples
223 ----------------------------------------
d074ca52 » stuartsierra
2011-07-01 Update README with latest release number and changes log
224
11a9bfc7 » stuartsierra
2012-02-09 Update README and namespace docstring
225 Copyright (c) Stuart Sierra, 2012. All rights reserved. The use and
226 distribution terms for this software are covered by the Eclipse Public
227 License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
228 be found in the file epl-v10.html at the root of this distribution.
229 By using this software in any fashion, you are agreeing to be bound by
230 the terms of this license. You must not remove this notice, or any
231 other, from this software.
Something went wrong with that request. Please try again.