File: //opt/alt/ruby32/share/gems/doc/json-2.16.0/ri/JSON/cdesc-JSON.ri
U:RDoc::NormalModule[iI" JSON:ET@0o:RDoc::Markup::Document:@parts[o;;[ :
@fileI"'ext/json/ext/generator/generator.c;T:0@omit_headings_from_table_of_contents_below0o;;[ ; I"!ext/json/ext/parser/parser.c;T;
0o;;[�S:RDoc::Markup::Heading:
leveli: textI"(JavaScript \Object Notation (\JSON);To:RDoc::Markup::BlankLine o:RDoc::Markup::Paragraph;[I"4\JSON is a lightweight data-interchange format.;T@o;;[I"+A \JSON value is one of the following:;To:RDoc::Markup::List:
@type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o;;[I")Double-quoted text: <tt>"foo"</tt>.;To;;0;[o;;[I""Number: +1+, +1.0+, +2.0e2+.;To;;0;[o;;[I"Boolean: +true+, +false+.;To;;0;[o;;[I"Null: +null+.;To;;0;[o;;[I"D\Array: an ordered list of values, enclosed by square brackets:;To:RDoc::Markup::Verbatim;[I"/["foo", 1, 1.0, 2.0e2, true, false, null]
;T:@format0o;;0;[o;;[I"J\Object: a collection of name/value pairs, enclosed by curly braces; ;TI"&each name is double-quoted text; ;TI"(the values may be any \JSON values:;To;;[I"R{"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}
;T;0o;;[I"MA \JSON array or object may contain nested arrays, objects, and scalars ;TI"to any depth:;To;;[I"5{"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}
;TI"([{"foo": 0, "bar": 1}, ["baz", 2]]
;T;0S;;i;
I"Using \Module \JSON;T@o;;[I"=To make module \JSON available in your code, begin with:;To;;[I"require 'json'
;T;0o;;[I"6All examples here assume that this has been done.;T@S;;i;
I"Parsing \JSON;T@o;;[I"9You can parse a \String containing \JSON data using ;TI"either of two methods:;To;;;;[o;;0;[o;;[I"&<tt>JSON.parse(source, opts)</tt>;To;;0;[o;;[I"'<tt>JSON.parse!(source, opts)</tt>;T@o;;[I"
where;To;;;;[o;;0;[o;;[I"+source+ is a Ruby object.;To;;0;[o;;[I"1+opts+ is a \Hash object containing options ;TI";that control both input allowed and output formatting.;T@o;;[
I",The difference between the two methods ;TI"+is that JSON.parse! omits some checks ;TI"1and may not be safe for some +source+ data; ;TI"0use it only for data from trusted sources. ;TI">Use the safer method JSON.parse for less trusted sources.;T@S;;i ;
I"Parsing \JSON Arrays;T@o;;[I"QWhen +source+ is a \JSON array, JSON.parse by default returns a Ruby \Array:;To;;[ I"8json = '["foo", 1, 1.0, 2.0e2, true, false, null]'
;TI"ruby = JSON.parse(json)
;TI"8ruby # => ["foo", 1, 1.0, 200.0, true, false, nil]
;TI"ruby.class # => Array
;T;0o;;[I"EThe \JSON array may contain nested arrays, objects, and scalars ;TI"to any depth:;To;;[I"1json = '[{"foo": 0, "bar": 1}, ["baz", 2]]'
;TI">JSON.parse(json) # => [{"foo"=>0, "bar"=>1}, ["baz", 2]]
;T;0S;;i ;
I"Parsing \JSON \Objects;T@o;;[I"SWhen the source is a \JSON object, JSON.parse by default returns a Ruby \Hash:;To;;[ I"[json = '{"a": "foo", "b": 1, "c": 1.0, "d": 2.0e2, "e": true, "f": false, "g": null}'
;TI"ruby = JSON.parse(json)
;TI"[ruby # => {"a"=>"foo", "b"=>1, "c"=>1.0, "d"=>200.0, "e"=>true, "f"=>false, "g"=>nil}
;TI"ruby.class # => Hash
;T;0o;;[I"FThe \JSON object may contain nested arrays, objects, and scalars ;TI"to any depth:;To;;[I">json = '{"foo": {"bar": 1, "baz": 2}, "bat": [0, 1, 2]}'
;TI"KJSON.parse(json) # => {"foo"=>{"bar"=>1, "baz"=>2}, "bat"=>[0, 1, 2]}
;T;0S;;i ;
I"Parsing \JSON Scalars;T@o;;[I"AWhen the source is a \JSON scalar (not an array or object), ;TI"&JSON.parse returns a Ruby scalar.;T@o;;[I"
\String:;To;;[I" ruby = JSON.parse('"foo"')
;TI"ruby # => 'foo'
;TI"ruby.class # => String
;T;0o;;[I"\Integer:;To;;[I"ruby = JSON.parse('1')
;TI"ruby # => 1
;TI"ruby.class # => Integer
;T;0o;;[I"\Float:;To;;[I"ruby = JSON.parse('1.0')
;TI"ruby # => 1.0
;TI"ruby.class # => Float
;TI" ruby = JSON.parse('2.0e2')
;TI"ruby # => 200
;TI"ruby.class # => Float
;T;0o;;[I"
Boolean:;To;;[I"ruby = JSON.parse('true')
;TI"ruby # => true
;TI"ruby.class # => TrueClass
;TI" ruby = JSON.parse('false')
;TI"ruby # => false
;TI" ruby.class # => FalseClass
;T;0o;;[I"
Null:;To;;[I"ruby = JSON.parse('null')
;TI"ruby # => nil
;TI"ruby.class # => NilClass
;T;0S;;i ;
I"Parsing Options;T@S;;i;
I"Input Options;T@o;;[I"ROption +max_nesting+ (\Integer) specifies the maximum nesting depth allowed; ;TI"Bdefaults to +100+; specify +false+ to disable depth checking.;T@o;;[I"With the default, +false+:;To;;[I"#source = '[0, [1, [2, [3]]]]'
;TI"ruby = JSON.parse(source)
;TI""ruby # => [0, [1, [2, [3]]]]
;T;0o;;[I"Too deep:;To;;[I"=# Raises JSON::NestingError (nesting of 2 is too deep):
;TI"*JSON.parse(source, {max_nesting: 1})
;T;0o;;[I"Bad value:;To;;[I"H# Raises TypeError (wrong argument type Symbol (expected Fixnum)):
;TI"-JSON.parse(source, {max_nesting: :foo})
;T;0S:RDoc::Markup::Rule:weighti@o;;[I"NOption +allow_duplicate_key+ specifies whether duplicate keys in objects ;TI"6should be ignored or cause an error to be raised:;T@o;;[I"When not specified:;To;;[ I"A# The last value is used and a deprecation warning emitted.
;TI"1JSON.parse('{"a": 1, "a":2}') => {"a" => 2}
;TI"8# warning: detected duplicate keys in JSON object.
;TI"[# This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
;T;0o;;[I"When set to `+true+`;To;;[I"# The last value is used.
;TI"1JSON.parse('{"a": 1, "a":2}') => {"a" => 2}
;T;0o;;[I"/When set to `+false+`, the future default:;To;;[I"[JSON.parse('{"a": 1, "a":2}') => duplicate key at line 1 column 1 (JSON::ParserError)
;T;0S;;i@o;;[I"=Option +allow_nan+ (boolean) specifies whether to allow ;TI"3NaN, Infinity, and MinusInfinity in +source+; ;TI"defaults to +false+.;T@o;;[I"With the default, +false+:;To;;[I"D# Raises JSON::ParserError (225: unexpected token at '[NaN]'):
;TI"JSON.parse('[NaN]')
;TI"I# Raises JSON::ParserError (232: unexpected token at '[Infinity]'):
;TI"JSON.parse('[Infinity]')
;TI"J# Raises JSON::ParserError (248: unexpected token at '[-Infinity]'):
;TI"JSON.parse('[-Infinity]')
;T;0o;;[I"Allow:;To;;[I"+source = '[NaN, Infinity, -Infinity]'
;TI"2ruby = JSON.parse(source, {allow_nan: true})
;TI"*ruby # => [NaN, Infinity, -Infinity]
;T;0S;;i@o;;[I"HOption +allow_trailing_comma+ (boolean) specifies whether to allow ;TI",trailing commas in objects and arrays; ;TI"defaults to +false+.;T@o;;[I"With the default, +false+:;To;;[I"[JSON.parse('[1,]') # unexpected character: ']' at line 1 column 4 (JSON::ParserError)
;T;0o;;[I"When enabled:;To;;[I"=JSON.parse('[1,]', allow_trailing_comma: true) # => [1]
;T;0S;;i;
I"Output Options;T@o;;[I"VOption +freeze+ (boolean) specifies whether the returned objects will be frozen; ;TI"defaults to +false+.;T@o;;[I"NOption +symbolize_names+ (boolean) specifies whether returned \Hash keys ;TI"should be Symbols; ;TI"'defaults to +false+ (use Strings).;T@o;;[I"With the default, +false+:;To;;[I"Isource = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
;TI"ruby = JSON.parse(source)
;TI"Gruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil}
;T;0o;;[I"Use Symbols:;To;;[I"8ruby = JSON.parse(source, {symbolize_names: true})
;TI"Bruby # => {:a=>"foo", :b=>1.0, :c=>true, :d=>false, :e=>nil}
;T;0S;;i@o;;[I"HOption +object_class+ (\Class) specifies the Ruby class to be used ;TI"for each \JSON object; ;TI"defaults to \Hash.;T@o;;[I"With the default, \Hash:;To;;[I"Isource = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}'
;TI"ruby = JSON.parse(source)
;TI"ruby.class # => Hash
;T;0o;;[I"Use class \OpenStruct:;To;;[I";ruby = JSON.parse(source, {object_class: OpenStruct})
;TI"Druby # => #<OpenStruct a="foo", b=1.0, c=true, d=false, e=nil>
;T;0S;;i@o;;[I"GOption +array_class+ (\Class) specifies the Ruby class to be used ;TI"for each \JSON array; ;TI"defaults to \Array.;T@o;;[I"With the default, \Array:;To;;[I"0source = '["foo", 1.0, true, false, null]'
;TI"ruby = JSON.parse(source)
;TI"ruby.class # => Array
;T;0o;;[I"Use class \Set:;To;;[I"3ruby = JSON.parse(source, {array_class: Set})
;TI"6ruby # => #<Set: {"foo", 1.0, true, false, nil}>
;T;0S;;i@o;;[I"^Option +create_additions+ (boolean) specifies whether to use \JSON additions in parsing. ;TI">See {\JSON Additions}[#module-JSON-label-JSON+Additions].;T@S;;i;
I"Generating \JSON;T@o;;[I"7To generate a Ruby \String containing \JSON data, ;TI";use method <tt>JSON.generate(source, opts)</tt>, where;To;;;;[o;;0;[o;;[I"+source+ is a Ruby object.;To;;0;[o;;[I"1+opts+ is a \Hash object containing options ;TI";that control both input allowed and output formatting.;T@S;;i ;
I"!Generating \JSON from Arrays;T@o;;[I"=When the source is a Ruby \Array, JSON.generate returns ;TI"(a \String containing a \JSON array:;To;;[I"ruby = [0, 's', :foo]
;TI" json = JSON.generate(ruby)
;TI"json # => '[0,"s","foo"]'
;T;0o;;[I"JThe Ruby \Array array may contain nested arrays, hashes, and scalars ;TI"to any depth:;To;;[I"*ruby = [0, [1, 2], {foo: 3, bar: 4}]
;TI" json = JSON.generate(ruby)
;TI"-json # => '[0,[1,2],{"foo":3,"bar":4}]'
;T;0S;;i ;
I"!Generating \JSON from Hashes;T@o;;[I"<When the source is a Ruby \Hash, JSON.generate returns ;TI")a \String containing a \JSON object:;To;;[I"*ruby = {foo: 0, bar: 's', baz: :bat}
;TI" json = JSON.generate(ruby)
;TI"1json # => '{"foo":0,"bar":"s","baz":"bat"}'
;T;0o;;[I"IThe Ruby \Hash array may contain nested arrays, hashes, and scalars ;TI"to any depth:;To;;[I"<ruby = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
;TI" json = JSON.generate(ruby)
;TI"Cjson # => '{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}'
;T;0S;;i ;
I"(Generating \JSON from Other Objects;T@o;;[I"7When the source is neither an \Array nor a \Hash, ;TI"Athe generated \JSON data depends on the class of the source.;T@o;;[I"IWhen the source is a Ruby \Integer or \Float, JSON.generate returns ;TI")a \String containing a \JSON number:;To;;[I"!JSON.generate(42) # => '42'
;TI"%JSON.generate(0.42) # => '0.42'
;T;0o;;[I">When the source is a Ruby \String, JSON.generate returns ;TI">a \String containing a \JSON string (with double-quotes):;To;;[I"1JSON.generate('A string') # => '"A string"'
;T;0o;;[I"HWhen the source is +true+, +false+ or +nil+, JSON.generate returns ;TI"8a \String containing the corresponding \JSON token:;To;;[I"%JSON.generate(true) # => 'true'
;TI"'JSON.generate(false) # => 'false'
;TI"$JSON.generate(nil) # => 'null'
;T;0o;;[I"AWhen the source is none of the above, JSON.generate returns ;TI"Fa \String containing a \JSON string representation of the source:;To;;[I"&JSON.generate(:foo) # => '"foo"'
;TI"0JSON.generate(Complex(0, 0)) # => '"0+0i"'
;TI"1JSON.generate(Dir.new('.')) # => '"#<Dir>"'
;T;0S;;i ;
I"Generating Options;T@S;;i;
I"Input Options;T@o;;[I"4Option +allow_nan+ (boolean) specifies whether ;TI"A+NaN+, +Infinity+, and <tt>-Infinity</tt> may be generated; ;TI"defaults to +false+.;T@o;;[I"With the default, +false+:;To;;[I"C# Raises JSON::GeneratorError (920: NaN not allowed in JSON):
;TI"JSON.generate(JSON::NaN)
;TI"H# Raises JSON::GeneratorError (917: Infinity not allowed in JSON):
;TI"#JSON.generate(JSON::Infinity)
;TI"I# Raises JSON::GeneratorError (917: -Infinity not allowed in JSON):
;TI"(JSON.generate(JSON::MinusInfinity)
;T;0o;;[I"Allow:;To;;[I"@ruby = [Float::NaN, Float::Infinity, Float::MinusInfinity]
;TI"JJSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,-Infinity]'
;T;0S;;i@o;;[I">Option +allow_duplicate_key+ (boolean) specifies whether ;TI"Ghashes with duplicate keys should be allowed or produce an error. ;TI",defaults to emit a deprecation warning.;T@o;;[I"!With the default, (not set):;To;;[
I"!Warning[:deprecated] = true
;TI"+JSON.generate({ foo: 1, "foo" => 2 })
;TI"F# warning: detected duplicate key "foo" in {foo: 1, "foo" => 2}.
;TI"[# This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`
;TI"# => '{"foo":1,"foo":2}'
;T;0o;;[I"With <tt>false</tt>;To;;[I"GJSON.generate({ foo: 1, "foo" => 2 }, allow_duplicate_key: false)
;TI"S# detected duplicate key "foo" in {foo: 1, "foo" => 2} (JSON::GeneratorError)
;T;0o;;[I"<In version 3.0, <tt>false</tt> will become the default.;T@S;;i@o;;[I"IOption +max_nesting+ (\Integer) specifies the maximum nesting depth ;TI"!in +obj+; defaults to +100+.;T@o;;[I"With the default, +100+:;To;;[I"obj = [[[[[[0]]]]]]
;TI"-JSON.generate(obj) # => '[[[[[[0]]]]]]'
;T;0o;;[I"Too deep:;To;;[I"=# Raises JSON::NestingError (nesting of 2 is too deep):
;TI"(JSON.generate(obj, max_nesting: 2)
;T;0S;;i;
I"Escaping Options;T@o;;[I"[Options +script_safe+ (boolean) specifies wether <tt>'\u2028'</tt>, <tt>'\u2029'</tt> ;TI"aand <tt>'/'</tt> should be escaped as to make the JSON object safe to interpolate in script ;TI"
tags.;T@o;;[I"\Options +ascii_only+ (boolean) specifies wether all characters outside the ASCII range ;TI"should be escaped.;T@S;;i;
I"Output Options;T@o;;[I">The default formatting options generate the most compact ;TI"8\JSON data, all on one line and with no whitespace.;T@o;;[I"6You can use these formatting options to generate ;TI"9\JSON data in a more open format, using whitespace. ;TI"#See also JSON.pretty_generate.;T@o;;;;[
o;;0;[o;;[I"HOption +array_nl+ (\String) specifies a string (usually a newline) ;TI"Wto be inserted after each \JSON array; defaults to the empty \String, <tt>''</tt>.;To;;0;[o;;[I"IOption +object_nl+ (\String) specifies a string (usually a newline) ;TI"Xto be inserted after each \JSON object; defaults to the empty \String, <tt>''</tt>.;To;;0;[o;;[ I"KOption +indent+ (\String) specifies the string (usually spaces) to be ;TI"Gused for indentation; defaults to the empty \String, <tt>''</tt>; ;TI"1defaults to the empty \String, <tt>''</tt>; ;TI"Mhas no effect unless options +array_nl+ or +object_nl+ specify newlines.;To;;0;[o;;[I"IOption +space+ (\String) specifies a string (usually a space) to be ;TI";inserted after the colon in each \JSON object's pair; ;TI"0defaults to the empty \String, <tt>''</tt>.;To;;0;[o;;[I"POption +space_before+ (\String) specifies a string (usually a space) to be ;TI"<inserted before the colon in each \JSON object's pair; ;TI"0defaults to the empty \String, <tt>''</tt>.;T@o;;[I"CIn this example, +obj+ is used first to generate the shortest ;TI"H\JSON data (no whitespace), then again with all formatting options ;TI"specified:;T@o;;[I"6obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}}
;TI"json = JSON.generate(obj)
;TI"puts 'Compact:', json
;TI"opts = {
;TI" array_nl: "\n",
;TI" object_nl: "\n",
;TI" indent: ' ',
;TI" space_before: ' ',
;TI" space: ' '
;TI"}
;TI",puts 'Open:', JSON.generate(obj, opts)
;T;0o;;[I"Output:;To;;[I"Compact:
;TI"3{"foo":["bar","baz"],"bat":{"bam":0,"bad":1}}
;TI"Open:
;TI"{
;TI" "foo" : [
;TI" "bar",
;TI" "baz"
;TI"],
;TI" "bat" : {
;TI" "bam" : 0,
;TI" "bad" : 1
;TI" }
;TI"}
;T;0S;;i;
I"\JSON Additions;T@o;;[I"JNote that JSON Additions must only be used with trusted data, and is ;TI"deprecated.;T@o;;[I"MWhen you "round trip" a non-\String object from Ruby to \JSON and back, ;TI"Byou have a new \String, instead of the object you began with:;To;;[I"ruby0 = Range.new(0, 2)
;TI"!json = JSON.generate(ruby0)
;TI"json # => '0..2"'
;TI"ruby1 = JSON.parse(json)
;TI"ruby1 # => '0..2'
;TI"ruby1.class # => String
;T;0o;;[I"DYou can use \JSON _additions_ to preserve the original object. ;TI";The addition is an extension of a ruby class, so that:;To;;;;[o;;0;[o;;[I"@\JSON.generate stores more information in the \JSON string.;To;;0;[o;;[I"9\JSON.parse, called with option +create_additions+, ;TI":uses that information to create a proper Ruby object.;T@o;;[I"<This example shows a \Range being generated into \JSON ;TI"6and parsed back into Ruby, both without and with ;TI"the addition for \Range:;To;;[I"ruby = Range.new(0, 2)
;TI"9# This passage does not use the addition for Range.
;TI"!json0 = JSON.generate(ruby)
;TI"ruby0 = JSON.parse(json0)
;TI"1# This passage uses the addition for Range.
;TI"require 'json/add/range'
;TI"!json1 = JSON.generate(ruby)
;TI"7ruby1 = JSON.parse(json1, create_additions: true)
;TI"# Make a nice display.
;TI"display = <<~EOT
;TI" Generated JSON:
;TI"6 Without addition: #{json0} (#{json0.class})
;TI"6 With addition: #{json1} (#{json1.class})
;TI" Parsed JSON:
;TI"> Without addition: #{ruby0.inspect} (#{ruby0.class})
;TI"> With addition: #{ruby1.inspect} (#{ruby1.class})
;TI" EOT
;TI"puts display
;T;0o;;[I"-This output shows the different results:;To;;[I"Generated JSON:
;TI"* Without addition: "0..2" (String)
;TI"J With addition: {"json_class":"Range","a":[0,2,false]} (String)
;TI"Parsed JSON:
;TI"* Without addition: "0..2" (String)
;TI"' With addition: 0..2 (Range)
;T;0o;;[I">The \JSON module includes additions for certain classes. ;TI"*You can also craft custom additions. ;TI"LSee {Custom \JSON Additions}[#module-JSON-label-Custom+JSON+Additions].;T@S;;i;
I"Built-in Additions;T@o;;[I">The \JSON module includes additions for certain classes. ;TI".To use an addition, +require+ its source:;To;;;;[o;;0;[o;;[I"7BigDecimal: <tt>require 'json/add/bigdecimal'</tt>;To;;0;[o;;[I"1Complex: <tt>require 'json/add/complex'</tt>;To;;0;[o;;[I"+Date: <tt>require 'json/add/date'</tt>;To;;0;[o;;[I"4DateTime: <tt>require 'json/add/date_time'</tt>;To;;0;[o;;[I"5Exception: <tt>require 'json/add/exception'</tt>;To;;0;[o;;[I"4OpenStruct: <tt>require 'json/add/ostruct'</tt>;To;;0;[o;;[I"-Range: <tt>require 'json/add/range'</tt>;To;;0;[o;;[I"3Rational: <tt>require 'json/add/rational'</tt>;To;;0;[o;;[I"/Regexp: <tt>require 'json/add/regexp'</tt>;To;;0;[o;;[I")Set: <tt>require 'json/add/set'</tt>;To;;0;[o;;[I"/Struct: <tt>require 'json/add/struct'</tt>;To;;0;[o;;[I"/Symbol: <tt>require 'json/add/symbol'</tt>;To;;0;[o;;[I"+Time: <tt>require 'json/add/time'</tt>;T@o;;[I"7To reduce punctuation clutter, the examples below ;TI"Jshow the generated \JSON via +puts+, rather than the usual +inspect+,;T@o;;[I"\BigDecimal:;To;;[
I"#require 'json/add/bigdecimal'
;TI"!ruby0 = BigDecimal(0) # 0.0
;TI"Ljson = JSON.generate(ruby0) # {"json_class":"BigDecimal","b":"27:0.0"}
;TI"<ruby1 = JSON.parse(json, create_additions: true) # 0.0
;TI"!ruby1.class # => BigDecimal
;T;0o;;[I"\Complex:;To;;[
I" require 'json/add/complex'
;TI""ruby0 = Complex(1+0i) # 1+0i
;TI"Hjson = JSON.generate(ruby0) # {"json_class":"Complex","r":1,"i":0}
;TI"=ruby1 = JSON.parse(json, create_additions: true) # 1+0i
;TI"ruby1.class # Complex
;T;0o;;[I"\Date:;To;;[
I"require 'json/add/date'
;TI"%ruby0 = Date.today # 2020-05-02
;TI"]json = JSON.generate(ruby0) # {"json_class":"Date","y":2020,"m":5,"d":2,"sg":2299161.0}
;TI"Cruby1 = JSON.parse(json, create_additions: true) # 2020-05-02
;TI"ruby1.class # Date
;T;0o;;[I"\DateTime:;To;;[
I""require 'json/add/date_time'
;TI"6ruby0 = DateTime.now # 2020-05-02T10:38:13-05:00
;TI"~json = JSON.generate(ruby0) # {"json_class":"DateTime","y":2020,"m":5,"d":2,"H":10,"M":38,"S":13,"of":"-5/24","sg":2299161.0}
;TI"Rruby1 = JSON.parse(json, create_additions: true) # 2020-05-02T10:38:13-05:00
;TI"ruby1.class # DateTime
;T;0o;;[I"=\Exception (and its subclasses including \RuntimeError):;To;;[I""require 'json/add/exception'
;TI"4ruby0 = Exception.new('A message') # A message
;TI"Wjson = JSON.generate(ruby0) # {"json_class":"Exception","m":"A message","b":null}
;TI"Bruby1 = JSON.parse(json, create_additions: true) # A message
;TI"ruby1.class # Exception
;TI"Cruby0 = RuntimeError.new('Another message') # Another message
;TI"`json = JSON.generate(ruby0) # {"json_class":"RuntimeError","m":"Another message","b":null}
;TI"Hruby1 = JSON.parse(json, create_additions: true) # Another message
;TI" ruby1.class # RuntimeError
;T;0o;;[I"\OpenStruct:;To;;[
I" require 'json/add/ostruct'
;TI"iruby0 = OpenStruct.new(name: 'Matz', language: 'Ruby') # #<OpenStruct name="Matz", language="Ruby">
;TI"ejson = JSON.generate(ruby0) # {"json_class":"OpenStruct","t":{"name":"Matz","language":"Ruby"}}
;TI"cruby1 = JSON.parse(json, create_additions: true) # #<OpenStruct name="Matz", language="Ruby">
;TI"ruby1.class # OpenStruct
;T;0o;;[I"\Range:;To;;[
I"require 'json/add/range'
;TI"$ruby0 = Range.new(0, 2) # 0..2
;TI"Jjson = JSON.generate(ruby0) # {"json_class":"Range","a":[0,2,false]}
;TI"=ruby1 = JSON.parse(json, create_additions: true) # 0..2
;TI"ruby1.class # Range
;T;0o;;[I"\Rational:;To;;[
I"!require 'json/add/rational'
;TI""ruby0 = Rational(1, 3) # 1/3
;TI"Ijson = JSON.generate(ruby0) # {"json_class":"Rational","n":1,"d":3}
;TI"<ruby1 = JSON.parse(json, create_additions: true) # 1/3
;TI"ruby1.class # Rational
;T;0o;;[I"
\Regexp:;To;;[
I"require 'json/add/regexp'
;TI"-ruby0 = Regexp.new('foo') # (?-mix:foo)
;TI"Kjson = JSON.generate(ruby0) # {"json_class":"Regexp","o":0,"s":"foo"}
;TI"Druby1 = JSON.parse(json, create_additions: true) # (?-mix:foo)
;TI"ruby1.class # Regexp
;T;0o;;[I"
\Set:;To;;[
I"require 'json/add/set'
;TI"4ruby0 = Set.new([0, 1, 2]) # #<Set: {0, 1, 2}>
;TI"Djson = JSON.generate(ruby0) # {"json_class":"Set","a":[0,1,2]}
;TI"Jruby1 = JSON.parse(json, create_additions: true) # #<Set: {0, 1, 2}>
;TI"ruby1.class # Set
;T;0o;;[I"
\Struct:;To;;[I"require 'json/add/struct'
;TI"7Customer = Struct.new(:name, :address) # Customer
;TI"cruby0 = Customer.new("Dave", "123 Main") # #<struct Customer name="Dave", address="123 Main">
;TI"Ujson = JSON.generate(ruby0) # {"json_class":"Customer","v":["Dave","123 Main"]}
;TI"kruby1 = JSON.parse(json, create_additions: true) # #<struct Customer name="Dave", address="123 Main">
;TI"ruby1.class # Customer
;T;0o;;[I"
\Symbol:;To;;[
I"require 'json/add/symbol'
;TI"ruby0 = :foo # foo
;TI"Ejson = JSON.generate(ruby0) # {"json_class":"Symbol","s":"foo"}
;TI"<ruby1 = JSON.parse(json, create_additions: true) # foo
;TI"ruby1.class # Symbol
;T;0o;;[I"\Time:;To;;[
I"require 'json/add/time'
;TI"2ruby0 = Time.now # 2020-05-02 11:28:26 -0500
;TI"Vjson = JSON.generate(ruby0) # {"json_class":"Time","s":1588436906,"n":840560000}
;TI"Rruby1 = JSON.parse(json, create_additions: true) # 2020-05-02 11:28:26 -0500
;TI"ruby1.class # Time
;T;0S;;i;
I"Custom \JSON Additions;T@o;;[I"2In addition to the \JSON additions provided, ;TI"0you can craft \JSON additions of your own, ;TI"Beither for Ruby built-in classes or for user-defined classes.;T@o;;[I"'Here's a user-defined class +Foo+:;To;;[I"class Foo
;TI" attr_accessor :bar, :baz
;TI" def initialize(bar, baz)
;TI" self.bar = bar
;TI" self.baz = baz
;TI" end
;TI" end
;T;0o;;[I"&Here's the \JSON addition for it:;To;;[I",# Extend class Foo with JSON addition.
;TI"class Foo
;TI"@ # Serialize Foo object with its class name and arguments
;TI" def to_json(*args)
;TI" {
;TI"/ JSON.create_id => self.class.name,
;TI"+ 'a' => [ bar, baz ]
;TI" }.to_json(*args)
;TI" end
;TI"P # Deserialize JSON string by constructing new Foo object with arguments.
;TI"$ def self.json_create(object)
;TI" new(*object['a'])
;TI" end
;TI" end
;T;0o;;[I"Demonstration:;To;;[I"require 'json'
;TI"/# This Foo object has no custom addition.
;TI"foo0 = Foo.new(0, 1)
;TI"!json0 = JSON.generate(foo0)
;TI"obj0 = JSON.parse(json0)
;TI"!# Lood the custom addition.
;TI"%require_relative 'foo_addition'
;TI")# This foo has the custom addition.
;TI"foo1 = Foo.new(0, 1)
;TI"!json1 = JSON.generate(foo1)
;TI"6obj1 = JSON.parse(json1, create_additions: true)
;TI"# Make a nice display.
;TI"display = <<~EOT
;TI" Generated JSON:
;TI"= Without custom addition: #{json0} (#{json0.class})
;TI"= With custom addition: #{json1} (#{json1.class})
;TI" Parsed JSON:
;TI"C Without custom addition: #{obj0.inspect} (#{obj0.class})
;TI"C With custom addition: #{obj1.inspect} (#{obj1.class})
;TI" EOT
;TI"puts display
;T;0o;;[I"Output:;T@o;;[I"Generated JSON:
;TI"F Without custom addition: "#<Foo:0x0000000006534e80>" (String)
;TI"I With custom addition: {"json_class":"Foo","a":[0,1]} (String)
;TI"Parsed JSON:
;TI"F Without custom addition: "#<Foo:0x0000000006534e80>" (String)
;TI"O With custom addition: #<Foo:0x0000000006473bb8 @bar=0, @baz=1> (Foo);T;0; I"lib/json.rb;T;
0o;;[ ; I"lib/json/common.rb;T;
0o;;[ ; I"lib/json/ext.rb;T;
0o;;[ ; I"$lib/json/ext/generator/state.rb;T;
0o;;[ ; I"lib/json/generic_object.rb;T;
0o;;[ ; I"'lib/json/truffle_ruby/generator.rb;T;
0o;;[ ; I"lib/json/version.rb;T;
0; 0;
0[[
I"generator;TI"R;T:publicTI"lib/json/common.rb;T[
I"parser;T@
;T@[
I"
state;TI"RW;T;T@[
U:RDoc::Constant[i I"NaN;TI"JSON::NaN;T;0o;;[ ; @�;
0@�@cRDoc::NormalModule0U;[i I"
Infinity;TI"JSON::Infinity;T;0o;;[ ; @�;
0@�@@0U;[i I"MinusInfinity;TI"JSON::MinusInfinity;T;0o;;[ ; @�;
0@�@@0U;[i I"
Fragment;TI"JSON::Fragment;T;0o;;[
o;;[I"<Fragment of JSON document that is to be included as is:;To;;[I"0fragment = JSON::Fragment.new("[1, 2, 3]")
;TI"3JSON.generate({ count: 3, items: fragments })
;T;0o;;[I"FThis allows to easily assemble multiple JSON fragments that have ;TI"Ibeen persisted somewhere without having to parse them nor resorting ;TI"to string interpolation.;T@o;;[I"HNote: no validation is performed on the provided string. It is the ;TI"Kresponsibility of the caller to ensure the string contains valid JSON.;T; @�;
0@�@@0U;[i I"PARSE_L_OPTIONS;TI"JSON::PARSE_L_OPTIONS;T:private0o;;[ ; @�;
0@�@@0U;[i I"PRETTY_GENERATE_OPTIONS;TI""JSON::PRETTY_GENERATE_OPTIONS;T;0o;;[ ; @�;
0@�@@0U;[i I"JSON_LOADED;TI"JSON::JSON_LOADED;T;0o;;[ ; @�;
0@�@@0U;[i I"VERSION;TI"JSON::VERSION;T;0o;;[ ; @;
0@@@0[ [[I"
class;T[[;[[I"[];T@[I"create_id;T@[I"create_id=;T@[:protected[ [;[[I"'deprecated_singleton_attr_accessor;T@[I"on_mixed_keys_hash;T@[I"
instance;T[[;[[I" dump;T@[I"fast_generate;T@[I"
generate;T@[I" load;T@[I"load_file;T@[I"load_file!;T@[I"
parse;T@[I"parse!;T@[I"pretty_generate;T@[I"unsafe_load;T@[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ; 0;
0[@@@�I"lib/json/add/bigdecimal.rb;TI"lib/json/add/complex.rb;TI"lib/json/add/date.rb;TI"lib/json/add/date_time.rb;TI"lib/json/add/exception.rb;TI"lib/json/add/ostruct.rb;TI"lib/json/add/range.rb;TI"lib/json/add/rational.rb;TI"lib/json/add/regexp.rb;TI"lib/json/add/set.rb;TI"lib/json/add/string.rb;TI"lib/json/add/struct.rb;TI"lib/json/add/symbol.rb;TI"lib/json/add/time.rb;T@�@�@�@ @@@cRDoc::TopLevel