json 1.0.0 → 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +503 -0
- data/LICENSE +56 -0
- data/README.md +416 -0
- data/ext/json/ext/fbuffer/fbuffer.h +187 -0
- data/ext/json/ext/generator/depend +1 -0
- data/ext/json/ext/generator/extconf.rb +2 -7
- data/ext/json/ext/generator/generator.c +1312 -338
- data/ext/json/ext/generator/generator.h +177 -0
- data/ext/json/ext/parser/depend +1 -0
- data/ext/json/ext/parser/extconf.rb +28 -5
- data/ext/json/ext/parser/parser.c +1349 -689
- data/ext/json/ext/parser/parser.h +96 -0
- data/ext/json/ext/parser/parser.rl +644 -188
- data/ext/json/extconf.rb +3 -0
- data/json.gemspec +68 -0
- data/lib/json/add/bigdecimal.rb +58 -0
- data/lib/json/add/complex.rb +51 -0
- data/lib/json/add/core.rb +12 -0
- data/lib/json/add/date.rb +54 -0
- data/lib/json/add/date_time.rb +67 -0
- data/lib/json/add/exception.rb +49 -0
- data/lib/json/add/ostruct.rb +54 -0
- data/lib/json/add/range.rb +54 -0
- data/lib/json/add/rational.rb +49 -0
- data/lib/json/add/regexp.rb +48 -0
- data/lib/json/add/set.rb +48 -0
- data/lib/json/add/struct.rb +52 -0
- data/lib/json/add/symbol.rb +48 -0
- data/lib/json/add/time.rb +59 -0
- data/lib/json/common.rb +588 -74
- data/lib/json/ext.rb +3 -1
- data/lib/json/generic_object.rb +75 -0
- data/lib/json/pure/generator.rb +311 -119
- data/lib/json/pure/parser.rb +182 -55
- data/lib/json/pure.rb +5 -65
- data/lib/json/version.rb +2 -1
- data/lib/json.rb +583 -196
- metadata +78 -137
- data/CHANGES +0 -25
- data/GPL +0 -340
- data/README +0 -77
- data/Rakefile +0 -250
- data/TODO +0 -1
- data/VERSION +0 -1
- data/benchmarks/benchmark.txt +0 -133
- data/benchmarks/benchmark_generator.rb +0 -44
- data/benchmarks/benchmark_parser.rb +0 -22
- data/benchmarks/benchmark_rails.rb +0 -26
- data/bin/edit_json.rb +0 -11
- data/data/example.json +0 -1
- data/data/index.html +0 -37
- data/data/prototype.js +0 -2515
- data/ext/json/ext/generator/Makefile +0 -149
- data/ext/json/ext/generator/unicode.c +0 -184
- data/ext/json/ext/generator/unicode.h +0 -40
- data/ext/json/ext/parser/Makefile +0 -149
- data/ext/json/ext/parser/unicode.c +0 -156
- data/ext/json/ext/parser/unicode.h +0 -44
- data/install.rb +0 -26
- data/lib/json/Array.xpm +0 -21
- data/lib/json/FalseClass.xpm +0 -21
- data/lib/json/Hash.xpm +0 -21
- data/lib/json/Key.xpm +0 -73
- data/lib/json/NilClass.xpm +0 -21
- data/lib/json/Numeric.xpm +0 -28
- data/lib/json/String.xpm +0 -96
- data/lib/json/TrueClass.xpm +0 -21
- data/lib/json/editor.rb +0 -1207
- data/lib/json/json.xpm +0 -1499
- data/tests/fixtures/fail1.json +0 -1
- data/tests/fixtures/fail10.json +0 -1
- data/tests/fixtures/fail11.json +0 -1
- data/tests/fixtures/fail12.json +0 -1
- data/tests/fixtures/fail13.json +0 -1
- data/tests/fixtures/fail14.json +0 -1
- data/tests/fixtures/fail15.json +0 -1
- data/tests/fixtures/fail16.json +0 -1
- data/tests/fixtures/fail17.json +0 -1
- data/tests/fixtures/fail19.json +0 -1
- data/tests/fixtures/fail2.json +0 -1
- data/tests/fixtures/fail20.json +0 -1
- data/tests/fixtures/fail21.json +0 -1
- data/tests/fixtures/fail22.json +0 -1
- data/tests/fixtures/fail23.json +0 -1
- data/tests/fixtures/fail24.json +0 -1
- data/tests/fixtures/fail25.json +0 -1
- data/tests/fixtures/fail26.json +0 -1
- data/tests/fixtures/fail27.json +0 -2
- data/tests/fixtures/fail28.json +0 -2
- data/tests/fixtures/fail3.json +0 -1
- data/tests/fixtures/fail4.json +0 -1
- data/tests/fixtures/fail5.json +0 -1
- data/tests/fixtures/fail6.json +0 -1
- data/tests/fixtures/fail7.json +0 -1
- data/tests/fixtures/fail8.json +0 -1
- data/tests/fixtures/fail9.json +0 -1
- data/tests/fixtures/pass1.json +0 -56
- data/tests/fixtures/pass18.json +0 -1
- data/tests/fixtures/pass2.json +0 -1
- data/tests/fixtures/pass3.json +0 -6
- data/tests/runner.rb +0 -24
- data/tests/test_json.rb +0 -235
- data/tests/test_json_addition.rb +0 -94
- data/tests/test_json_fixtures.rb +0 -30
- data/tests/test_json_generate.rb +0 -81
- data/tests/test_json_unicode.rb +0 -55
- data/tools/fuzz.rb +0 -133
- data/tools/server.rb +0 -62
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
#frozen_string_literal: false
|
3
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
4
|
+
require 'json'
|
5
|
+
end
|
6
|
+
|
7
|
+
class Symbol
|
8
|
+
|
9
|
+
# Methods <tt>Symbol#as_json</tt> and +Symbol.json_create+ may be used
|
10
|
+
# to serialize and deserialize a \Symbol object;
|
11
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
12
|
+
#
|
13
|
+
# \Method <tt>Symbol#as_json</tt> serializes +self+,
|
14
|
+
# returning a 2-element hash representing +self+:
|
15
|
+
#
|
16
|
+
# require 'json/add/symbol'
|
17
|
+
# x = :foo.as_json
|
18
|
+
# # => {"json_class"=>"Symbol", "s"=>"foo"}
|
19
|
+
#
|
20
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Symbol object:
|
21
|
+
#
|
22
|
+
# Symbol.json_create(x) # => :foo
|
23
|
+
#
|
24
|
+
def as_json(*)
|
25
|
+
{
|
26
|
+
JSON.create_id => self.class.name,
|
27
|
+
's' => to_s,
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns a JSON string representing +self+:
|
32
|
+
#
|
33
|
+
# require 'json/add/symbol'
|
34
|
+
# puts :foo.to_json
|
35
|
+
#
|
36
|
+
# Output:
|
37
|
+
#
|
38
|
+
# # {"json_class":"Symbol","s":"foo"}
|
39
|
+
#
|
40
|
+
def to_json(*a)
|
41
|
+
as_json.to_json(*a)
|
42
|
+
end
|
43
|
+
|
44
|
+
# See #as_json.
|
45
|
+
def self.json_create(o)
|
46
|
+
o['s'].to_sym
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#frozen_string_literal: false
|
2
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
3
|
+
require 'json'
|
4
|
+
end
|
5
|
+
|
6
|
+
class Time
|
7
|
+
|
8
|
+
# See #as_json.
|
9
|
+
def self.json_create(object)
|
10
|
+
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
|
11
|
+
object['n'] = usec * 1000
|
12
|
+
end
|
13
|
+
if method_defined?(:tv_nsec)
|
14
|
+
at(object['s'], Rational(object['n'], 1000))
|
15
|
+
else
|
16
|
+
at(object['s'], object['n'] / 1000)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Methods <tt>Time#as_json</tt> and +Time.json_create+ may be used
|
21
|
+
# to serialize and deserialize a \Time object;
|
22
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
23
|
+
#
|
24
|
+
# \Method <tt>Time#as_json</tt> serializes +self+,
|
25
|
+
# returning a 2-element hash representing +self+:
|
26
|
+
#
|
27
|
+
# require 'json/add/time'
|
28
|
+
# x = Time.now.as_json
|
29
|
+
# # => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}
|
30
|
+
#
|
31
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Time object:
|
32
|
+
#
|
33
|
+
# Time.json_create(x)
|
34
|
+
# # => 2023-11-25 11:00:56.472846644 -0600
|
35
|
+
#
|
36
|
+
def as_json(*)
|
37
|
+
nanoseconds = [ tv_usec * 1000 ]
|
38
|
+
respond_to?(:tv_nsec) and nanoseconds << tv_nsec
|
39
|
+
nanoseconds = nanoseconds.max
|
40
|
+
{
|
41
|
+
JSON.create_id => self.class.name,
|
42
|
+
's' => tv_sec,
|
43
|
+
'n' => nanoseconds,
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns a JSON string representing +self+:
|
48
|
+
#
|
49
|
+
# require 'json/add/time'
|
50
|
+
# puts Time.now.to_json
|
51
|
+
#
|
52
|
+
# Output:
|
53
|
+
#
|
54
|
+
# {"json_class":"Time","s":1700931678,"n":980650786}
|
55
|
+
#
|
56
|
+
def to_json(*args)
|
57
|
+
as_json.to_json(*args)
|
58
|
+
end
|
59
|
+
end
|