Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 441 lines (338 sloc) 20.254 kb
6248665 ready for use with limitations
Peter Ohler authored
1 # Oj gem
2 A fast JSON parser and Object marshaller as a Ruby gem.
3
4 ## <a name="installation">Installation</a>
5 gem install oj
6
03e53b8 updated readme
Peter Ohler authored
7 ## <a name="documentation">Documentation</a>
6248665 ready for use with limitations
Peter Ohler authored
8
a758900 updated readme
Peter Ohler authored
9 *Documentation*: http://www.ohler.com/oj
1ee8e1f updated readme
Peter Ohler authored
10
11 ## <a name="source">Source</a>
12
6248665 ready for use with limitations
Peter Ohler authored
13 *GitHub* *repo*: https://github.com/ohler55/oj
14
15 *RubyGems* *repo*: https://rubygems.org/gems/oj
16
1ee8e1f updated readme
Peter Ohler authored
17 ## <a name="follow">Follow @oxgem on Twitter</a>
18
19 [Follow @peterohler on Twitter](http://twitter.com/#!/peterohler) for announcements and news about the Oj gem.
20
6248665 ready for use with limitations
Peter Ohler authored
21 ## <a name="build_status">Build Status</a>
22
da0330c getting the travis image to show status
Peter Ohler authored
23 [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
6248665 ready for use with limitations
Peter Ohler authored
24
25 ## <a name="links">Links of Interest</a>
26
e900e8e updated links and home page
Peter Ohler authored
27 [Need for Speed](http://www.ohler.com/dev/need_for_speed/need_for_speed.html) for an overview of how Oj::Doc was designed.
f5aae61 docs completed, ready for a release
Peter Ohler authored
28
afe4e99 changed json object format
Peter Ohler authored
29 *Fast XML parser and marshaller on RubyGems*: https://rubygems.org/gems/ox
6248665 ready for use with limitations
Peter Ohler authored
30
db33462 @MSNexploder fixed ox GitHub link
MSNexploder authored
31 *Fast XML parser and marshaller on GitHub*: https://github.com/ohler55/ox
57afd74 fixed a few bugs and added options
Peter Ohler authored
32
afe4e99 changed json object format
Peter Ohler authored
33 ## <a name="release">Release Notes</a>
6248665 ready for use with limitations
Peter Ohler authored
34
0e7afa0 fixed double free bug
Peter Ohler authored
35 ### Release 1.2.13
36
37 - Fixed double free bug in Oj::Doc that showed up for larger documents.
38
39423df fixed GC bug in Oj::Doc
Peter Ohler authored
39 ### Release 1.2.12
e27b76d added option to control maximum stack use for JSON strings
Peter Ohler authored
40
39423df fixed GC bug in Oj::Doc
Peter Ohler authored
41 - Fixed GC bug in Oj::Doc, the fast parser.
499d9c8 almost ready for 1.2.10 release
Peter Ohler authored
42
48d57be exception serialization now supported in 1.8.7
Peter Ohler authored
43 - Serialization of Exceptions in Ruby 1.8.7 now includes message and backtrace.
44
6248665 ready for use with limitations
Peter Ohler authored
45 ## <a name="description">Description</a>
46
47 Optimized JSON (Oj), as the name implies was written to provide speed
48 optimized JSON handling. It was designed as a faster alternative to Yajl and
49 other the common Ruby JSON parsers. So far is has achieved that at about 2
50 time faster than Yajl for parsing and 3 or more times faster writing JSON.
51
8711c85 serializes any Object now. Tests added as well.
Peter Ohler authored
52 Oj has several dump or serialization modes which control how Objects are
1a4aead @mat :effort parameter really is :mode.
mat authored
53 converted to JSON. These modes are set with the :mode option in either the
e0fb1d3 updatings docs and notes
Peter Ohler authored
54 default options or as one of the options to the dump() method.
55
56 - :strict mode will only allow the 7 basic JSON types to be serialized. Any other Object
57 will raise and Exception.
58
59 - :null mode replaces any Object that is not one of the JSON types is replaced by a JSON null.
60
61 - :object mode will dump any Object as a JSON Object with keys that match the
62 Ruby Object's variable names without the '@' character. This is the highest
63 performance mode.
64
65 - :compat mode is is the compatible with other systems. It will serialize any
66 Object but will check to see if the Object implements a to_hash() or to_json()
67 method. If either exists that method is used for serializing the Object. The
68 to_hash() is more flexible and produces more consistent output so it has a
69 preference over the to_json() method. If neither the to_json() or to_hash()
70 methods exist then the Oj internal Object variable encoding is used.
8711c85 serializes any Object now. Tests added as well.
Peter Ohler authored
71
4c6363a added comment in readme about using jruby
Peter Ohler authored
72 Oj is compatible with Ruby 1.8.7, 1.9.2, 1.9.3, JRuby, RBX, and the latest
73 2.0dev. Note that JRuby now disables support for extentions by default. JRuby
74 can be build with extensions enabled. Check the documenation for JRuby
75 installs in your environment.
d4a2c32 updated readme
Peter Ohler authored
76
77 Oj is also compatible with Rails. Just make sure the Oj gem is installed and
78 [multi_json](https://github.com/intridea/multi_json) will pick it up and use it.
5b248cc added Bag class and auto_define flag
Peter Ohler authored
79
6669206 ready for 0.6.0 release
Peter Ohler authored
80 ## <a name="compare">Comparisons</a>
81
f5aae61 docs completed, ready for a release
Peter Ohler authored
82 ### Fast Oj::Doc parser comparisons
83
84 The fast Oj::Doc parser is compared to the Yajl and JSON::Pure parsers with
85 strict JSON documents. No object conversions are included, just simple JSON.
86
87 Since the Oj::Doc deviation from the conventional parsers comparisons of not
88 only parsing but data access is also included. These tests use the
89 perf_fast.rb test file. The first benchmark is for just parsing. The second is
90 for doing a get on every leaf value in the JSON data structure. The third
91 fetchs a value from a specific spot in the document. With Yajl and JSON this
92 is done with a set of calls to fetch() for each level in the document. For
93 Oj::Doc a single fetch with a path is used.
94
95 The benchmark results are:
96
97 > perf_fast.rb -g 1 -f
98 --------------------------------------------------------------------------------
99 Parse Performance
100 Oj::Doc.parse 100000 times in 0.164 seconds or 609893.696 parse/sec.
101 Yajl.parse 100000 times in 3.168 seconds or 31569.902 parse/sec.
102 JSON::Ext.parse 100000 times in 3.282 seconds or 30464.826 parse/sec.
103
104 Summary:
105 System time (secs) rate (ops/sec)
106 --------- ----------- --------------
107 Oj::Doc 0.164 609893.696
108 Yajl 3.168 31569.902
109 JSON::Ext 3.282 30464.826
110
111 Comparison Matrix
112 (performance factor, 2.0 row is means twice as fast as column)
113 Oj::Doc Yajl JSON::Ext
114 --------- --------- --------- ---------
115 Oj::Doc 1.00 19.32 20.02
116 Yajl 0.05 1.00 1.04
117 JSON::Ext 0.05 0.96 1.00
118
119 --------------------------------------------------------------------------------
120 Parse and get all values Performance
121 Oj::Doc.parse 100000 times in 0.417 seconds or 240054.540 parse/sec.
122 Yajl.parse 100000 times in 5.159 seconds or 19384.191 parse/sec.
123 JSON::Ext.parse 100000 times in 5.269 seconds or 18978.638 parse/sec.
124
125 Summary:
126 System time (secs) rate (ops/sec)
127 --------- ----------- --------------
128 Oj::Doc 0.417 240054.540
129 Yajl 5.159 19384.191
130 JSON::Ext 5.269 18978.638
131
132 Comparison Matrix
133 (performance factor, 2.0 row is means twice as fast as column)
134 Oj::Doc Yajl JSON::Ext
135 --------- --------- --------- ---------
136 Oj::Doc 1.00 12.38 12.65
137 Yajl 0.08 1.00 1.02
138 JSON::Ext 0.08 0.98 1.00
139
140 --------------------------------------------------------------------------------
141 fetch nested Performance
142 Oj::Doc.fetch 100000 times in 0.094 seconds or 1059995.760 fetch/sec.
143 Ruby.fetch 100000 times in 0.503 seconds or 198851.434 fetch/sec.
144
145 Summary:
146 System time (secs) rate (ops/sec)
147 ------- ----------- --------------
148 Oj::Doc 0.094 1059995.760
149 Ruby 0.503 198851.434
150
151 Comparison Matrix
152 (performance factor, 2.0 row is means twice as fast as column)
153 Oj::Doc Ruby
154 ------- ------- -------
155 Oj::Doc 1.00 5.33
156 Ruby 0.19 1.00
157
158 What the results mean are that for getting just a few values from a JSON
159 document Oj::Doc is 20 times faster than any other parser and for accessing
160 all values it is still over 12 times faster than any other Ruby JSON parser.
161
162 ### Conventional Oj parser comparisons
163
6669206 ready for 0.6.0 release
Peter Ohler authored
164 The following table shows the difference is speeds between several
f5aae61 docs completed, ready for a release
Peter Ohler authored
165 serialization packages compared to the more conventional Oj parser. The tests
166 had to be scaled back due to limitation of some of the gems. I finally gave up
167 trying to get JSON Pure to serialize without errors with Ruby 1.9.3. It had
168 internal errors on anything other than a simple JSON structure. The errors
169 encountered were:
6669206 ready for 0.6.0 release
Peter Ohler authored
170
171 - MessagePack fails to convert Bignum to JSON
172
e0fb1d3 updatings docs and notes
Peter Ohler authored
173 - JSON Pure fails to serialize any numbers or Objects with the to_json() method
6669206 ready for 0.6.0 release
Peter Ohler authored
174
e0fb1d3 updatings docs and notes
Peter Ohler authored
175 Options were added to the test/perf_strict.rb test to run the test without
176 Object encoding and without Bignums.
6669206 ready for 0.6.0 release
Peter Ohler authored
177
178 None of the packages except Oj were able to serialize Ruby Objects that did
179 not have a to_json() method or were of the 7 native JSON types.
180
5b248cc added Bag class and auto_define flag
Peter Ohler authored
181 A perf_obj.rb file was added for comparing different Object marshalling
182 packages.
183
6669206 ready for 0.6.0 release
Peter Ohler authored
184 It is also worth noting that although Oj is slightly behind MessagePack for
185 parsing, Oj serialization is much faster than MessagePack even though Oj uses
186 human readable JSON vs the binary MessagePack format.
187
f5aae61 docs completed, ready for a release
Peter Ohler authored
188 Oj supports circular references when in :object mode and when the :circular
6b22c57 finishing off circular reference implementation
Peter Ohler authored
189 flag is true. None of the other gems tested supported circular
190 references. They failed in the following manners when the input included
191 circular references.
192
193 - Yajl core dumps Ruby
194
195 - JSON fails and raises an Exception
196
197 - MessagePack fails and raises an Exception
198
199 The benchmark results are:
6669206 ready for 0.6.0 release
Peter Ohler authored
200
201 with Object and Bignum encoding:
202
53e3bbc added benchmarks
Peter Ohler authored
203 > perf_strict.rb
6234873 ready for a release
Peter Ohler authored
204 --------------------------------------------------------------------------------
205 Load/Parse Performance
53e3bbc added benchmarks
Peter Ohler authored
206 Oj:compat.load 100000 times in 1.481 seconds or 67513.146 load/sec.
207 Oj.load 100000 times in 1.066 seconds or 93796.400 load/sec.
208 JSON::Ext.parse 100000 times in 3.023 seconds or 33074.875 parse/sec.
209 JSON::Pure.parse 100000 times in 18.908 seconds or 5288.799 parse/sec.
210 Ox.load 100000 times in 1.240 seconds or 80671.900 load/sec.
6234873 ready for a release
Peter Ohler authored
211
212 Summary:
213 System time (secs) rate (ops/sec)
214 ---------- ----------- --------------
53e3bbc added benchmarks
Peter Ohler authored
215 Oj 1.066 93796.400
216 Ox 1.240 80671.900
217 Oj:compat 1.481 67513.146
218 JSON::Ext 3.023 33074.875
219 JSON::Pure 18.908 5288.799
6234873 ready for a release
Peter Ohler authored
220
221 Comparison Matrix
222 (performance factor, 2.0 row is means twice as fast as column)
53e3bbc added benchmarks
Peter Ohler authored
223 Oj Ox Oj:compat JSON::Ext JSON::Pure
6234873 ready for a release
Peter Ohler authored
224 ---------- ---------- ---------- ---------- ---------- ----------
53e3bbc added benchmarks
Peter Ohler authored
225 Oj 1.00 1.16 1.39 2.84 17.73
226 Ox 0.86 1.00 1.19 2.44 15.25
227 Oj:compat 0.72 0.84 1.00 2.04 12.77
228 JSON::Ext 0.35 0.41 0.49 1.00 6.25
229 JSON::Pure 0.06 0.07 0.08 0.16 1.00
6234873 ready for a release
Peter Ohler authored
230
231
232 --------------------------------------------------------------------------------
233 Dump/Encode/Generate Performance
53e3bbc added benchmarks
Peter Ohler authored
234 Oj:compat.dump 100000 times in 0.789 seconds or 126715.249 dump/sec.
235 Oj.dump 100000 times in 0.457 seconds or 218798.751 dump/sec.
236 JSON::Ext.generate 100000 times in 4.371 seconds or 22878.630 generate/sec.
237 Ox.dump 100000 times in 0.501 seconds or 199425.256 dump/sec.
6234873 ready for a release
Peter Ohler authored
238
239 Summary:
240 System time (secs) rate (ops/sec)
241 --------- ----------- --------------
53e3bbc added benchmarks
Peter Ohler authored
242 Oj 0.457 218798.751
243 Ox 0.501 199425.256
244 Oj:compat 0.789 126715.249
245 JSON::Ext 4.371 22878.630
6234873 ready for a release
Peter Ohler authored
246
247 Comparison Matrix
248 (performance factor, 2.0 row is means twice as fast as column)
53e3bbc added benchmarks
Peter Ohler authored
249 Oj Ox Oj:compat JSON::Ext
6234873 ready for a release
Peter Ohler authored
250 --------- --------- --------- --------- ---------
53e3bbc added benchmarks
Peter Ohler authored
251 Oj 1.00 1.10 1.73 9.56
252 Ox 0.91 1.00 1.57 8.72
253 Oj:compat 0.58 0.64 1.00 5.54
254 JSON::Ext 0.10 0.11 0.18 1.00
255
256
257 The following packages were not included for the reason listed
258 ***** MessagePack: RangeError: bignum too big to convert into `unsigned long long'
259 ***** Yajl: RuntimeError: Yajl parse and encode did not return the same object as the original.
260 ***** JSON::Pure: TypeError: wrong argument type JSON::Pure::Generator::State (expected Data)
6669206 ready for 0.6.0 release
Peter Ohler authored
261
53e3bbc added benchmarks
Peter Ohler authored
262 without Objects or numbers (for JSON Pure, Yajl, and Messagepack) JSON:
6669206 ready for 0.6.0 release
Peter Ohler authored
263
6234873 ready for a release
Peter Ohler authored
264 --------------------------------------------------------------------------------
265 Load/Parse Performance
53e3bbc added benchmarks
Peter Ohler authored
266 Oj:compat.load 100000 times in 0.806 seconds or 124051.164 load/sec.
267 Oj.load 100000 times in 0.810 seconds or 123384.587 load/sec.
268 Yajl.parse 100000 times in 1.441 seconds or 69385.996 parse/sec.
269 JSON::Ext.parse 100000 times in 1.567 seconds or 63797.848 parse/sec.
270 JSON::Pure.parse 100000 times in 13.500 seconds or 7407.247 parse/sec.
271 Ox.load 100000 times in 0.954 seconds or 104836.748 load/sec.
272 MessagePack.unpack 100000 times in 0.651 seconds or 153707.817 unpack/sec.
6234873 ready for a release
Peter Ohler authored
273
274 Summary:
275 System time (secs) rate (ops/sec)
276 ----------- ----------- --------------
53e3bbc added benchmarks
Peter Ohler authored
277 MessagePack 0.651 153707.817
278 Oj:compat 0.806 124051.164
279 Oj 0.810 123384.587
280 Ox 0.954 104836.748
281 Yajl 1.441 69385.996
282 JSON::Ext 1.567 63797.848
283 JSON::Pure 13.500 7407.247
6234873 ready for a release
Peter Ohler authored
284
285 Comparison Matrix
286 (performance factor, 2.0 row is means twice as fast as column)
53e3bbc added benchmarks
Peter Ohler authored
287 MessagePack Oj:compat Oj Ox Yajl JSON::Ext JSON::Pure
288 ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
289 MessagePack 1.00 1.24 1.25 1.47 2.22 2.41 20.75
290 Oj:compat 0.81 1.00 1.01 1.18 1.79 1.94 16.75
291 Oj 0.80 0.99 1.00 1.18 1.78 1.93 16.66
292 Ox 0.68 0.85 0.85 1.00 1.51 1.64 14.15
293 Yajl 0.45 0.56 0.56 0.66 1.00 1.09 9.37
294 JSON::Ext 0.42 0.51 0.52 0.61 0.92 1.00 8.61
295 JSON::Pure 0.05 0.06 0.06 0.07 0.11 0.12 1.00
6234873 ready for a release
Peter Ohler authored
296
297
298 --------------------------------------------------------------------------------
299 Dump/Encode/Generate Performance
53e3bbc added benchmarks
Peter Ohler authored
300 Oj:compat.dump 100000 times in 0.173 seconds or 578526.262 dump/sec.
301 Oj.dump 100000 times in 0.179 seconds or 558362.880 dump/sec.
302 Yajl.encode 100000 times in 0.776 seconds or 128794.279 encode/sec.
303 JSON::Ext.generate 100000 times in 3.511 seconds or 28483.812 generate/sec.
304 JSON::Pure.generate 100000 times in 7.389 seconds or 13533.717 generate/sec.
305 Ox.dump 100000 times in 0.196 seconds or 510589.629 dump/sec.
306 MessagePack.pack 100000 times in 0.317 seconds or 315307.220 pack/sec.
6234873 ready for a release
Peter Ohler authored
307
308 Summary:
309 System time (secs) rate (ops/sec)
310 ----------- ----------- --------------
53e3bbc added benchmarks
Peter Ohler authored
311 Oj:compat 0.173 578526.262
312 Oj 0.179 558362.880
313 Ox 0.196 510589.629
314 MessagePack 0.317 315307.220
315 Yajl 0.776 128794.279
316 JSON::Ext 3.511 28483.812
317 JSON::Pure 7.389 13533.717
6234873 ready for a release
Peter Ohler authored
318
319 Comparison Matrix
320 (performance factor, 2.0 row is means twice as fast as column)
53e3bbc added benchmarks
Peter Ohler authored
321 Oj:compat Oj Ox MessagePack Yajl JSON::Ext JSON::Pure
322 ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
323 Oj:compat 1.00 1.04 1.13 1.83 4.49 20.31 42.75
324 Oj 0.97 1.00 1.09 1.77 4.34 19.60 41.26
325 Ox 0.88 0.91 1.00 1.62 3.96 17.93 37.73
326 MessagePack 0.55 0.56 0.62 1.00 2.45 11.07 23.30
327 Yajl 0.22 0.23 0.25 0.41 1.00 4.52 9.52
328 JSON::Ext 0.05 0.05 0.06 0.09 0.22 1.00 2.10
329 JSON::Pure 0.02 0.02 0.03 0.04 0.11 0.48 1.00
6234873 ready for a release
Peter Ohler authored
330
6248665 ready for use with limitations
Peter Ohler authored
331 ### Simple JSON Writing and Parsing:
332
333 require 'oj'
334
335 h = { 'one' => 1, 'array' => [ true, false ] }
336 json = Oj.dump(h)
337
338 # json =
339 # {
340 # "one":1,
341 # "array":[
342 # true,
343 # false
344 # ]
345 # }
346
9b9a86f @sferik Fix typo
sferik authored
347 h2 = Oj.load(json)
6248665 ready for use with limitations
Peter Ohler authored
348 puts "Same? #{h == h2}"
349 # true
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
350
351 ### Object JSON format:
352
353 In :object mode Oj generates JSON that follows conventions which allow Class
354 and other information such as Object IDs for circular reference detection. The
355 formating follows the following rules.
356
357 1. JSON native types, true, false, nil, String, Hash, Array, and Number are
358 encoded normally.
359
6b22c57 finishing off circular reference implementation
Peter Ohler authored
360 2. A Symbol is encoded as a JSON string with a preceeding `:` character.
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
361
6b22c57 finishing off circular reference implementation
Peter Ohler authored
362 3. The `^` character denotes a special key value when in a JSON Object sequence.
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
363
6b22c57 finishing off circular reference implementation
Peter Ohler authored
364 4. A Ruby String that starts with `:` or the sequence `^i` or `^r` are encoded by
365 excaping the first character so that it appears as `\u005e` or `\u003a` instead of
366 `:` or `^`.
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
367
6b22c57 finishing off circular reference implementation
Peter Ohler authored
368 5. A `"^c"` JSON Object key indicates the value should be converted to a Ruby
369 class. The sequence `{"^c":"Oj::Bag"}` is read as the Oj::Bag class.
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
370
6b22c57 finishing off circular reference implementation
Peter Ohler authored
371 6. A `"^t"` JSON Object key indicates the value should be converted to a Ruby
c9bb99f adding new encodings
Peter Ohler authored
372 Time. The sequence `{"^t":1325775487.000000}` is read as Jan 5, 2012 at
499d9c8 almost ready for 1.2.10 release
Peter Ohler authored
373 23:58:07.
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
374
c9bb99f adding new encodings
Peter Ohler authored
375 7. A `"^o"` JSON Object key indicates the value should be converted to a Ruby
6b22c57 finishing off circular reference implementation
Peter Ohler authored
376 Object. The first entry in the JSON Object must be a class with the `"^o"`
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
377 key. After that each entry is treated as a variable of the Object where the
6b22c57 finishing off circular reference implementation
Peter Ohler authored
378 key is the variable name without the preceeding `@`. An example is
499d9c8 almost ready for 1.2.10 release
Peter Ohler authored
379 `{"^o":"Oj::Bag","x":58,"y":"marbles"}`. `"^O"` is the same except that it is
380 for built in or odd classes that don't obey the normal Ruby rules. Examples
381 are Rational, Date, and DateTime.
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
382
6b22c57 finishing off circular reference implementation
Peter Ohler authored
383 8. A `"^u"` JSON Object key indicates the value should be converted to a Ruby
384 Struct. The first entry in the JSON Object must be a class with the `"^u"`
0dfa515 now dumping struct in the correct format. Loading still unimplemented
Peter Ohler authored
385 key. After that each entry is is given a numeric position in the struct and
6b22c57 finishing off circular reference implementation
Peter Ohler authored
386 that is used as the key in the JSON Object. An example is `{"^u":["Range",1,7,false]}`.
0dfa515 now dumping struct in the correct format. Loading still unimplemented
Peter Ohler authored
387
6b22c57 finishing off circular reference implementation
Peter Ohler authored
388 9. When encoding an Object, if the variable name does not begin with an `@`
389 character then the name preceeded by a `~` character. This occurs in the
390 Exception class. An example is `{"^o":"StandardError","~mesg":"A Message","~bt":[".\/tests.rb:345:in `test_exception'"]}`.
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
391
6b22c57 finishing off circular reference implementation
Peter Ohler authored
392 10. If a Hash entry has a key that is not a String or Symbol then the entry is
393 encoded with a key of the form `"^#n"` where n is a hex number. The value that
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
394 is an Array where the first element is the key in the Hash and the second is
6b22c57 finishing off circular reference implementation
Peter Ohler authored
395 the value. An example is `{"^#3":[2,5]}`.
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
396
6b22c57 finishing off circular reference implementation
Peter Ohler authored
397 11. A `"^i"` JSON entry in either an Object or Array is the ID of the Ruby
4d28d2c updated readme with message format for object encoding
Peter Ohler authored
398 Object being encoded. It is used when the :circular flag is set. It can appear
6b22c57 finishing off circular reference implementation
Peter Ohler authored
399 in either a JSON Object or in a JSON Array. In an Object the `"^i"` key has a
fdacd8d added hash circular support
Peter Ohler authored
400 corresponding reference Fixnum. In an array the sequence will include an
401 embedded reference number. An example is
6b22c57 finishing off circular reference implementation
Peter Ohler authored
402 `{"^o":"Oj::Bag","^i":1,"x":["^i2",true],"me":"^r1"}`.
403
404 12. A `"^r"` JSON entry in an Object is a references to a Object or Array that
405 already appears in the JSON String. It must match up with a previous `"^i"`
406 ID. An example is `{"^o":"Oj::Bag","^i":1,"x":3,"me":"^r1"}`.
fdacd8d added hash circular support
Peter Ohler authored
407
6b22c57 finishing off circular reference implementation
Peter Ohler authored
408 13. If an Array element is a String and starts with `"^i"` then the first
409 character, the `^` is encoded as a hex character sequence. An example is
410 `["\u005ei37",3]`.
fdacd8d added hash circular support
Peter Ohler authored
411
6b22c57 finishing off circular reference implementation
Peter Ohler authored
412 ### License:
413
414 Copyright (c) 2012, Peter Ohler
415 All rights reserved.
416
417 Redistribution and use in source and binary forms, with or without
418 modification, are permitted provided that the following conditions are met:
419
420 - Redistributions of source code must retain the above copyright notice, this
421 list of conditions and the following disclaimer.
422
423 - Redistributions in binary form must reproduce the above copyright notice,
424 this list of conditions and the following disclaimer in the documentation
425 and/or other materials provided with the distribution.
426
427 - Neither the name of Peter Ohler nor the names of its contributors may be
428 used to endorse or promote products derived from this software without
429 specific prior written permission.
430
431 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
432 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
433 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
434 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
435 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
436 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
437 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
438 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
439 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
440 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Something went wrong with that request. Please try again.