json 1.0.0 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +503 -0
  3. data/LICENSE +56 -0
  4. data/README.md +416 -0
  5. data/ext/json/ext/fbuffer/fbuffer.h +187 -0
  6. data/ext/json/ext/generator/depend +1 -0
  7. data/ext/json/ext/generator/extconf.rb +2 -7
  8. data/ext/json/ext/generator/generator.c +1312 -338
  9. data/ext/json/ext/generator/generator.h +177 -0
  10. data/ext/json/ext/parser/depend +1 -0
  11. data/ext/json/ext/parser/extconf.rb +28 -5
  12. data/ext/json/ext/parser/parser.c +1349 -689
  13. data/ext/json/ext/parser/parser.h +96 -0
  14. data/ext/json/ext/parser/parser.rl +644 -188
  15. data/ext/json/extconf.rb +3 -0
  16. data/json.gemspec +68 -0
  17. data/lib/json/add/bigdecimal.rb +58 -0
  18. data/lib/json/add/complex.rb +51 -0
  19. data/lib/json/add/core.rb +12 -0
  20. data/lib/json/add/date.rb +54 -0
  21. data/lib/json/add/date_time.rb +67 -0
  22. data/lib/json/add/exception.rb +49 -0
  23. data/lib/json/add/ostruct.rb +54 -0
  24. data/lib/json/add/range.rb +54 -0
  25. data/lib/json/add/rational.rb +49 -0
  26. data/lib/json/add/regexp.rb +48 -0
  27. data/lib/json/add/set.rb +48 -0
  28. data/lib/json/add/struct.rb +52 -0
  29. data/lib/json/add/symbol.rb +48 -0
  30. data/lib/json/add/time.rb +59 -0
  31. data/lib/json/common.rb +588 -74
  32. data/lib/json/ext.rb +3 -1
  33. data/lib/json/generic_object.rb +75 -0
  34. data/lib/json/pure/generator.rb +311 -119
  35. data/lib/json/pure/parser.rb +182 -55
  36. data/lib/json/pure.rb +5 -65
  37. data/lib/json/version.rb +2 -1
  38. data/lib/json.rb +583 -196
  39. metadata +78 -137
  40. data/CHANGES +0 -25
  41. data/GPL +0 -340
  42. data/README +0 -77
  43. data/Rakefile +0 -250
  44. data/TODO +0 -1
  45. data/VERSION +0 -1
  46. data/benchmarks/benchmark.txt +0 -133
  47. data/benchmarks/benchmark_generator.rb +0 -44
  48. data/benchmarks/benchmark_parser.rb +0 -22
  49. data/benchmarks/benchmark_rails.rb +0 -26
  50. data/bin/edit_json.rb +0 -11
  51. data/data/example.json +0 -1
  52. data/data/index.html +0 -37
  53. data/data/prototype.js +0 -2515
  54. data/ext/json/ext/generator/Makefile +0 -149
  55. data/ext/json/ext/generator/unicode.c +0 -184
  56. data/ext/json/ext/generator/unicode.h +0 -40
  57. data/ext/json/ext/parser/Makefile +0 -149
  58. data/ext/json/ext/parser/unicode.c +0 -156
  59. data/ext/json/ext/parser/unicode.h +0 -44
  60. data/install.rb +0 -26
  61. data/lib/json/Array.xpm +0 -21
  62. data/lib/json/FalseClass.xpm +0 -21
  63. data/lib/json/Hash.xpm +0 -21
  64. data/lib/json/Key.xpm +0 -73
  65. data/lib/json/NilClass.xpm +0 -21
  66. data/lib/json/Numeric.xpm +0 -28
  67. data/lib/json/String.xpm +0 -96
  68. data/lib/json/TrueClass.xpm +0 -21
  69. data/lib/json/editor.rb +0 -1207
  70. data/lib/json/json.xpm +0 -1499
  71. data/tests/fixtures/fail1.json +0 -1
  72. data/tests/fixtures/fail10.json +0 -1
  73. data/tests/fixtures/fail11.json +0 -1
  74. data/tests/fixtures/fail12.json +0 -1
  75. data/tests/fixtures/fail13.json +0 -1
  76. data/tests/fixtures/fail14.json +0 -1
  77. data/tests/fixtures/fail15.json +0 -1
  78. data/tests/fixtures/fail16.json +0 -1
  79. data/tests/fixtures/fail17.json +0 -1
  80. data/tests/fixtures/fail19.json +0 -1
  81. data/tests/fixtures/fail2.json +0 -1
  82. data/tests/fixtures/fail20.json +0 -1
  83. data/tests/fixtures/fail21.json +0 -1
  84. data/tests/fixtures/fail22.json +0 -1
  85. data/tests/fixtures/fail23.json +0 -1
  86. data/tests/fixtures/fail24.json +0 -1
  87. data/tests/fixtures/fail25.json +0 -1
  88. data/tests/fixtures/fail26.json +0 -1
  89. data/tests/fixtures/fail27.json +0 -2
  90. data/tests/fixtures/fail28.json +0 -2
  91. data/tests/fixtures/fail3.json +0 -1
  92. data/tests/fixtures/fail4.json +0 -1
  93. data/tests/fixtures/fail5.json +0 -1
  94. data/tests/fixtures/fail6.json +0 -1
  95. data/tests/fixtures/fail7.json +0 -1
  96. data/tests/fixtures/fail8.json +0 -1
  97. data/tests/fixtures/fail9.json +0 -1
  98. data/tests/fixtures/pass1.json +0 -56
  99. data/tests/fixtures/pass18.json +0 -1
  100. data/tests/fixtures/pass2.json +0 -1
  101. data/tests/fixtures/pass3.json +0 -6
  102. data/tests/runner.rb +0 -24
  103. data/tests/test_json.rb +0 -235
  104. data/tests/test_json_addition.rb +0 -94
  105. data/tests/test_json_fixtures.rb +0 -30
  106. data/tests/test_json_generate.rb +0 -81
  107. data/tests/test_json_unicode.rb +0 -55
  108. data/tools/fuzz.rb +0 -133
  109. 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