json 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of json might be problematic. Click here for more details.
- data/CHANGES +8 -0
- data/Gemfile +3 -5
- data/Rakefile +34 -5
- data/VERSION +1 -1
- data/bin/prettify_json.rb +12 -39
- data/ext/json/ext/generator/generator.c +62 -22
- data/ext/json/ext/generator/generator.h +5 -2
- data/ext/json/ext/parser/parser.c +496 -285
- data/ext/json/ext/parser/parser.h +5 -1
- data/ext/json/ext/parser/parser.rl +155 -81
- data/java/src/json/ext/Generator.java +5 -5
- data/java/src/json/ext/GeneratorMethods.java +8 -7
- data/java/src/json/ext/GeneratorService.java +5 -4
- data/java/src/json/ext/GeneratorState.java +44 -16
- data/java/src/json/ext/OptionsReader.java +3 -3
- data/java/src/json/ext/Parser.java +399 -117
- data/java/src/json/ext/Parser.rl +118 -38
- data/java/src/json/ext/ParserService.java +4 -3
- data/java/src/json/ext/RuntimeInfo.java +23 -21
- data/java/src/json/ext/Utils.java +2 -2
- data/json.gemspec +17 -17
- data/json_pure.gemspec +22 -16
- data/lib/json.rb +7 -7
- data/lib/json/add/complex.rb +22 -0
- data/lib/json/add/core.rb +9 -9
- data/lib/json/add/rational.rb +22 -0
- data/lib/json/common.rb +50 -38
- data/lib/json/editor.rb +16 -16
- data/lib/json/ext.rb +2 -15
- data/lib/json/pure/generator.rb +18 -3
- data/lib/json/pure/parser.rb +92 -58
- data/lib/json/version.rb +1 -1
- data/tests/test_json.rb +52 -1
- data/tests/test_json_addition.rb +9 -2
- data/tests/test_json_generate.rb +34 -1
- data/tools/fuzz.rb +1 -1
- metadata +50 -52
- data/lib/json/add/rails.rb +0 -8
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
|
3
|
-
*
|
3
|
+
*
|
4
4
|
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
|
5
5
|
* for details.
|
6
6
|
*/
|
@@ -66,7 +66,7 @@ final class Utils {
|
|
66
66
|
static RaiseException newException(ThreadContext context,
|
67
67
|
String className, RubyString message) {
|
68
68
|
RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
|
69
|
-
RubyClass klazz = info.jsonModule.getClass(className);
|
69
|
+
RubyClass klazz = info.jsonModule.get().getClass(className);
|
70
70
|
RubyException excptn =
|
71
71
|
(RubyException)klazz.newInstance(context,
|
72
72
|
new IRubyObject[] {message}, Block.NULL_BLOCK);
|
data/json.gemspec
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "1.5.
|
4
|
+
s.name = "json"
|
5
|
+
s.version = "1.5.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.executables = [
|
13
|
-
s.extensions = [
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
s.files = [
|
16
|
-
s.homepage =
|
17
|
-
s.rdoc_options = [
|
18
|
-
s.require_paths = [
|
19
|
-
s.rubyforge_project =
|
20
|
-
s.rubygems_version =
|
21
|
-
s.summary =
|
22
|
-
s.test_files = [
|
8
|
+
s.authors = ["Florian Frank"]
|
9
|
+
s.date = "2011-08-31"
|
10
|
+
s.description = "This is a JSON implementation as a Ruby extension in C."
|
11
|
+
s.email = "flori@ping.de"
|
12
|
+
s.executables = ["edit_json.rb", "prettify_json.rb"]
|
13
|
+
s.extensions = ["ext/json/ext/parser/extconf.rb", "ext/json/ext/generator/extconf.rb"]
|
14
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
15
|
+
s.files = ["tests", "tests/test_json_string_matching.rb", "tests/test_json_fixtures.rb", "tests/setup_variant.rb", "tests/fixtures", "tests/fixtures/fail6.json", "tests/fixtures/fail9.json", "tests/fixtures/fail10.json", "tests/fixtures/fail24.json", "tests/fixtures/fail28.json", "tests/fixtures/fail13.json", "tests/fixtures/fail4.json", "tests/fixtures/pass3.json", "tests/fixtures/fail11.json", "tests/fixtures/fail14.json", "tests/fixtures/fail3.json", "tests/fixtures/fail12.json", "tests/fixtures/pass16.json", "tests/fixtures/pass15.json", "tests/fixtures/fail20.json", "tests/fixtures/fail8.json", "tests/fixtures/pass2.json", "tests/fixtures/fail5.json", "tests/fixtures/fail1.json", "tests/fixtures/fail25.json", "tests/fixtures/pass17.json", "tests/fixtures/fail7.json", "tests/fixtures/pass26.json", "tests/fixtures/fail21.json", "tests/fixtures/pass1.json", "tests/fixtures/fail23.json", "tests/fixtures/fail18.json", "tests/fixtures/fail2.json", "tests/fixtures/fail22.json", "tests/fixtures/fail27.json", "tests/fixtures/fail19.json", "tests/test_json_unicode.rb", "tests/test_json_addition.rb", "tests/test_json_generate.rb", "tests/test_json_encoding.rb", "tests/test_json.rb", "COPYING", "TODO", "Rakefile", "benchmarks", "benchmarks/data-p4-3GHz-ruby18", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat", "benchmarks/parser2_benchmark.rb", "benchmarks/parser_benchmark.rb", "benchmarks/generator2_benchmark.rb", "benchmarks/generator_benchmark.rb", "benchmarks/ohai.ruby", "benchmarks/data", "benchmarks/ohai.json", "lib", "lib/json", "lib/json/json.xpm", "lib/json/TrueClass.xpm", "lib/json/version.rb", "lib/json/Array.xpm", "lib/json/add", "lib/json/add/complex.rb", "lib/json/add/rational.rb", "lib/json/add/core.rb", "lib/json/common.rb", "lib/json/pure", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/ext.rb", "lib/json/pure.rb", "lib/json/Key.xpm", "lib/json/FalseClass.xpm", "lib/json/editor.rb", "lib/json/Numeric.xpm", "lib/json/ext", "lib/json/NilClass.xpm", "lib/json/String.xpm", "lib/json/Hash.xpm", "lib/json.rb", "Gemfile", "README.rdoc", "json_pure.gemspec", "GPL", "CHANGES", "bin", "bin/prettify_json.rb", "bin/edit_json.rb", "COPYING-json-jruby", "ext", "ext/json", "ext/json/ext", "ext/json/ext/parser", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.rl", "ext/json/ext/parser/parser.c", "ext/json/ext/generator", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.h", "VERSION", "data", "data/prototype.js", "data/index.html", "data/example.json", "json.gemspec", "java", "java/src", "java/src/json", "java/src/json/ext", "java/src/json/ext/Parser.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/ParserService.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/Utils.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/GeneratorMethods.java", "java/lib", "java/lib/bytelist-1.0.6.jar", "java/lib/jcodings.jar", "diagrams", "README-json-jruby.markdown", "install.rb", "json-java.gemspec", "tools", "tools/fuzz.rb", "tools/server.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json.rb"]
|
16
|
+
s.homepage = "http://flori.github.com/json"
|
17
|
+
s.rdoc_options = ["--title", "JSON implemention for Ruby", "--main", "README.rdoc"]
|
18
|
+
s.require_paths = ["ext/json/ext", "ext", "lib"]
|
19
|
+
s.rubyforge_project = "json"
|
20
|
+
s.rubygems_version = "1.8.10"
|
21
|
+
s.summary = "JSON Implementation for Ruby"
|
22
|
+
s.test_files = ["./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json.rb"]
|
23
23
|
|
24
24
|
if s.respond_to? :specification_version then
|
25
25
|
s.specification_version = 3
|
data/json_pure.gemspec
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "1.5.
|
4
|
+
s.name = "json_pure"
|
5
|
+
s.version = "1.5.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.executables = [
|
13
|
-
s.extra_rdoc_files = [
|
14
|
-
s.files = [
|
15
|
-
s.homepage =
|
16
|
-
s.rdoc_options = [
|
17
|
-
s.require_paths = [
|
18
|
-
s.rubyforge_project =
|
19
|
-
s.rubygems_version =
|
20
|
-
s.summary =
|
21
|
-
s.test_files = [
|
8
|
+
s.authors = ["Florian Frank"]
|
9
|
+
s.date = "2011-08-31"
|
10
|
+
s.description = "This is a JSON implementation in pure Ruby."
|
11
|
+
s.email = "flori@ping.de"
|
12
|
+
s.executables = ["edit_json.rb", "prettify_json.rb"]
|
13
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
14
|
+
s.files = ["tests", "tests/test_json_string_matching.rb", "tests/test_json_fixtures.rb", "tests/setup_variant.rb", "tests/fixtures", "tests/fixtures/fail6.json", "tests/fixtures/fail9.json", "tests/fixtures/fail10.json", "tests/fixtures/fail24.json", "tests/fixtures/fail28.json", "tests/fixtures/fail13.json", "tests/fixtures/fail4.json", "tests/fixtures/pass3.json", "tests/fixtures/fail11.json", "tests/fixtures/fail14.json", "tests/fixtures/fail3.json", "tests/fixtures/fail12.json", "tests/fixtures/pass16.json", "tests/fixtures/pass15.json", "tests/fixtures/fail20.json", "tests/fixtures/fail8.json", "tests/fixtures/pass2.json", "tests/fixtures/fail5.json", "tests/fixtures/fail1.json", "tests/fixtures/fail25.json", "tests/fixtures/pass17.json", "tests/fixtures/fail7.json", "tests/fixtures/pass26.json", "tests/fixtures/fail21.json", "tests/fixtures/pass1.json", "tests/fixtures/fail23.json", "tests/fixtures/fail18.json", "tests/fixtures/fail2.json", "tests/fixtures/fail22.json", "tests/fixtures/fail27.json", "tests/fixtures/fail19.json", "tests/test_json_unicode.rb", "tests/test_json_addition.rb", "tests/test_json_generate.rb", "tests/test_json_encoding.rb", "tests/test_json.rb", "COPYING", "TODO", "Rakefile", "benchmarks", "benchmarks/data-p4-3GHz-ruby18", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat", "benchmarks/parser2_benchmark.rb", "benchmarks/parser_benchmark.rb", "benchmarks/generator2_benchmark.rb", "benchmarks/generator_benchmark.rb", "benchmarks/ohai.ruby", "benchmarks/data", "benchmarks/ohai.json", "lib", "lib/json", "lib/json/json.xpm", "lib/json/TrueClass.xpm", "lib/json/version.rb", "lib/json/Array.xpm", "lib/json/add", "lib/json/add/complex.rb", "lib/json/add/rational.rb", "lib/json/add/core.rb", "lib/json/common.rb", "lib/json/pure", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/ext.rb", "lib/json/pure.rb", "lib/json/Key.xpm", "lib/json/FalseClass.xpm", "lib/json/editor.rb", "lib/json/Numeric.xpm", "lib/json/ext", "lib/json/NilClass.xpm", "lib/json/String.xpm", "lib/json/Hash.xpm", "lib/json.rb", "Gemfile", "README.rdoc", "json_pure.gemspec", "GPL", "CHANGES", "bin", "bin/prettify_json.rb", "bin/edit_json.rb", "COPYING-json-jruby", "ext", "ext/json", "ext/json/ext", "ext/json/ext/parser", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.rl", "ext/json/ext/parser/parser.c", "ext/json/ext/generator", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.h", "VERSION", "data", "data/prototype.js", "data/index.html", "data/example.json", "json.gemspec", "java", "java/src", "java/src/json", "java/src/json/ext", "java/src/json/ext/Parser.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/ParserService.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/Utils.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/GeneratorMethods.java", "java/lib", "java/lib/bytelist-1.0.6.jar", "java/lib/jcodings.jar", "diagrams", "README-json-jruby.markdown", "install.rb", "json-java.gemspec", "tools", "tools/fuzz.rb", "tools/server.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json.rb"]
|
15
|
+
s.homepage = "http://flori.github.com/json"
|
16
|
+
s.rdoc_options = ["--title", "JSON implemention for ruby", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = "json"
|
19
|
+
s.rubygems_version = "1.8.10"
|
20
|
+
s.summary = "JSON Implementation for Ruby"
|
21
|
+
s.test_files = ["./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json.rb"]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
s.specification_version = 3
|
@@ -27,14 +27,20 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.add_development_dependency(%q<permutation>, [">= 0"])
|
28
28
|
s.add_development_dependency(%q<bullshit>, [">= 0"])
|
29
29
|
s.add_development_dependency(%q<sdoc>, [">= 0"])
|
30
|
+
s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
|
31
|
+
s.add_runtime_dependency(%q<spruz>, ["~> 0.2.8"])
|
30
32
|
else
|
31
33
|
s.add_dependency(%q<permutation>, [">= 0"])
|
32
34
|
s.add_dependency(%q<bullshit>, [">= 0"])
|
33
35
|
s.add_dependency(%q<sdoc>, [">= 0"])
|
36
|
+
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
37
|
+
s.add_dependency(%q<spruz>, ["~> 0.2.8"])
|
34
38
|
end
|
35
39
|
else
|
36
40
|
s.add_dependency(%q<permutation>, [">= 0"])
|
37
41
|
s.add_dependency(%q<bullshit>, [">= 0"])
|
38
42
|
s.add_dependency(%q<sdoc>, [">= 0"])
|
43
|
+
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
44
|
+
s.add_dependency(%q<spruz>, ["~> 0.2.8"])
|
39
45
|
end
|
40
46
|
end
|
data/lib/json.rb
CHANGED
@@ -7,15 +7,15 @@
|
|
7
7
|
#
|
8
8
|
# Built on two universally available structures:
|
9
9
|
# 1. A collection of name/value pairs. Often referred to as an _object_, hash table, record, struct, keyed list, or associative array.
|
10
|
-
# 2. An
|
10
|
+
# 2. An ordered list of values. More commonly called an _array_, vector, sequence or list.
|
11
11
|
#
|
12
12
|
# To read more about JSON visit: http://json.org
|
13
13
|
#
|
14
14
|
# == Parsing JSON
|
15
15
|
#
|
16
|
-
# To parse a JSON string received by another application
|
16
|
+
# To parse a JSON string received by another application or generated within
|
17
17
|
# your existing application:
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# require 'json'
|
20
20
|
#
|
21
21
|
# my_hash = JSON.parse('{"hello": "goodbye"}')
|
@@ -32,7 +32,7 @@
|
|
32
32
|
# just as simple.
|
33
33
|
#
|
34
34
|
# require 'json'
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# my_hash = {:hello => "goodbye"}
|
37
37
|
# puts JSON.generate(my_hash) => "{\"hello\":\"goodbye\"}"
|
38
38
|
#
|
@@ -41,9 +41,9 @@
|
|
41
41
|
# require 'json'
|
42
42
|
# puts {:hello => "goodbye"}.to_json => "{\"hello\":\"goodbye\"}"
|
43
43
|
#
|
44
|
-
# <tt>JSON.generate</tt> only allows objects or arrays to be converted
|
45
|
-
# to JSON syntax.
|
46
|
-
# even though it only
|
44
|
+
# <tt>JSON.generate</tt> only allows objects or arrays to be converted
|
45
|
+
# to JSON syntax. <tt>to_json</tt>, however, accepts many Ruby classes
|
46
|
+
# even though it acts only as a method for serialization:
|
47
47
|
#
|
48
48
|
# require 'json'
|
49
49
|
#
|
@@ -0,0 +1,22 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
defined?(::Complex) or require 'complex'
|
5
|
+
|
6
|
+
class Complex
|
7
|
+
def self.json_create(object)
|
8
|
+
Complex(object['r'], object['i'])
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json(*)
|
12
|
+
{
|
13
|
+
JSON.create_id => self.class.name,
|
14
|
+
'r' => real,
|
15
|
+
'i' => imag,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json(*)
|
20
|
+
as_json.to_json
|
21
|
+
end
|
22
|
+
end
|
data/lib/json/add/core.rb
CHANGED
@@ -21,7 +21,7 @@ class Symbol
|
|
21
21
|
def to_json(*a)
|
22
22
|
as_json.to_json(*a)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# Deserializes JSON string by converting the <tt>string</tt> value stored in the object to a Symbol
|
26
26
|
def self.json_create(o)
|
27
27
|
o['s'].to_sym
|
@@ -52,7 +52,7 @@ class Time
|
|
52
52
|
'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
|
53
53
|
}
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
# Stores class name (Time) with number of seconds since epoch and number of
|
57
57
|
# microseconds for Time as JSON string
|
58
58
|
def to_json(*args)
|
@@ -62,7 +62,7 @@ end
|
|
62
62
|
|
63
63
|
# Date serialization/deserialization
|
64
64
|
class Date
|
65
|
-
|
65
|
+
|
66
66
|
# Deserializes JSON string by converting Julian year <tt>y</tt>, month
|
67
67
|
# <tt>m</tt>, day <tt>d</tt> and Day of Calendar Reform <tt>sg</tt> to Date.
|
68
68
|
def self.json_create(object)
|
@@ -80,7 +80,7 @@ class Date
|
|
80
80
|
'm' => month,
|
81
81
|
'd' => day,
|
82
82
|
'sg' => start,
|
83
|
-
}
|
83
|
+
}
|
84
84
|
end
|
85
85
|
|
86
86
|
# Stores class name (Date) with Julian year <tt>y</tt>, month <tt>m</tt>, day
|
@@ -123,7 +123,7 @@ class DateTime
|
|
123
123
|
'S' => sec,
|
124
124
|
'of' => offset.to_s,
|
125
125
|
'sg' => start,
|
126
|
-
}
|
126
|
+
}
|
127
127
|
end
|
128
128
|
|
129
129
|
# Stores class name (DateTime) with Julian year <tt>y</tt>, month <tt>m</tt>,
|
@@ -136,7 +136,7 @@ end
|
|
136
136
|
|
137
137
|
# Range serialization/deserialization
|
138
138
|
class Range
|
139
|
-
|
139
|
+
|
140
140
|
# Deserializes JSON string by constructing new Range object with arguments
|
141
141
|
# <tt>a</tt> serialized by <tt>to_json</tt>.
|
142
142
|
def self.json_create(object)
|
@@ -162,7 +162,7 @@ end
|
|
162
162
|
|
163
163
|
# Struct serialization/deserialization
|
164
164
|
class Struct
|
165
|
-
|
165
|
+
|
166
166
|
# Deserializes JSON string by constructing new Struct object with values
|
167
167
|
# <tt>v</tt> serialized by <tt>to_json</tt>.
|
168
168
|
def self.json_create(object)
|
@@ -230,8 +230,8 @@ class Regexp
|
|
230
230
|
def as_json(*)
|
231
231
|
{
|
232
232
|
JSON.create_id => self.class.name,
|
233
|
-
'o'
|
234
|
-
's'
|
233
|
+
'o' => options,
|
234
|
+
's' => source,
|
235
235
|
}
|
236
236
|
end
|
237
237
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
defined?(::Rational) or require 'rational'
|
5
|
+
|
6
|
+
class Rational
|
7
|
+
def self.json_create(object)
|
8
|
+
Rational(object['n'], object['d'])
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json(*)
|
12
|
+
{
|
13
|
+
JSON.create_id => self.class.name,
|
14
|
+
'n' => numerator,
|
15
|
+
'd' => denominator,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json(*)
|
20
|
+
as_json.to_json
|
21
|
+
end
|
22
|
+
end
|
data/lib/json/common.rb
CHANGED
@@ -2,11 +2,11 @@ require 'json/version'
|
|
2
2
|
|
3
3
|
module JSON
|
4
4
|
class << self
|
5
|
-
# If _object_ is string-like parse the string and return the parsed result
|
5
|
+
# If _object_ is string-like, parse the string and return the parsed result
|
6
6
|
# as a Ruby data structure. Otherwise generate a JSON text from the Ruby
|
7
7
|
# data structure object and return it.
|
8
8
|
#
|
9
|
-
# The _opts_ argument is passed through to generate/parse respectively
|
9
|
+
# The _opts_ argument is passed through to generate/parse respectively. See
|
10
10
|
# generate and parse for their documentation.
|
11
11
|
def [](object, opts = {})
|
12
12
|
if object.respond_to? :to_str
|
@@ -16,7 +16,7 @@ module JSON
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
# Returns the JSON parser class
|
19
|
+
# Returns the JSON parser class that is used by JSON. This is either
|
20
20
|
# JSON::Ext::Parser or JSON::Pure::Parser.
|
21
21
|
attr_reader :parser
|
22
22
|
|
@@ -28,7 +28,7 @@ module JSON
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# Return the constant located at _path_. The format of _path_ has to be
|
31
|
-
# either ::A::B::C or A::B::C. In any case A has to be located at the top
|
31
|
+
# either ::A::B::C or A::B::C. In any case, A has to be located at the top
|
32
32
|
# level (absolute namespace path?). If there doesn't exist a constant at
|
33
33
|
# the given path, an ArgumentError is raised.
|
34
34
|
def deep_const_get(path) # :nodoc:
|
@@ -81,15 +81,15 @@ module JSON
|
|
81
81
|
$VERBOSE = old
|
82
82
|
end
|
83
83
|
|
84
|
-
# Returns the JSON generator
|
84
|
+
# Returns the JSON generator module that is used by JSON. This is
|
85
85
|
# either JSON::Ext::Generator or JSON::Pure::Generator.
|
86
86
|
attr_reader :generator
|
87
87
|
|
88
|
-
# Returns the JSON generator state class
|
89
|
-
#
|
88
|
+
# Returns the JSON generator state class that is used by JSON. This is
|
89
|
+
# either JSON::Ext::Generator::State or JSON::Pure::Generator::State.
|
90
90
|
attr_accessor :state
|
91
91
|
|
92
|
-
# This is create identifier,
|
92
|
+
# This is create identifier, which is used to decide if the _json_create_
|
93
93
|
# hook of a class should be called. It defaults to 'json_class'.
|
94
94
|
attr_accessor :create_id
|
95
95
|
end
|
@@ -104,10 +104,10 @@ module JSON
|
|
104
104
|
# The base exception for JSON errors.
|
105
105
|
class JSONError < StandardError; end
|
106
106
|
|
107
|
-
# This exception is raised
|
107
|
+
# This exception is raised if a parser error occurs.
|
108
108
|
class ParserError < JSONError; end
|
109
109
|
|
110
|
-
# This exception is raised
|
110
|
+
# This exception is raised if the nesting of parsed data structures is too
|
111
111
|
# deep.
|
112
112
|
class NestingError < ParserError; end
|
113
113
|
|
@@ -115,13 +115,13 @@ module JSON
|
|
115
115
|
class CircularDatastructure < NestingError; end
|
116
116
|
# :startdoc:
|
117
117
|
|
118
|
-
# This exception is raised
|
118
|
+
# This exception is raised if a generator or unparser error occurs.
|
119
119
|
class GeneratorError < JSONError; end
|
120
120
|
# For backwards compatibility
|
121
121
|
UnparserError = GeneratorError
|
122
122
|
|
123
|
-
# This exception is raised
|
124
|
-
# system. Usually this means
|
123
|
+
# This exception is raised if the required unicode support is missing on the
|
124
|
+
# system. Usually this means that the iconv library is not installed.
|
125
125
|
class MissingUnicodeSupport < JSONError; end
|
126
126
|
|
127
127
|
module_function
|
@@ -131,16 +131,16 @@ module JSON
|
|
131
131
|
# _opts_ can have the following
|
132
132
|
# keys:
|
133
133
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
134
|
-
# structures. Disable depth checking with :max_nesting => false
|
134
|
+
# structures. Disable depth checking with :max_nesting => false. It defaults
|
135
135
|
# to 19.
|
136
136
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
137
137
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
138
138
|
# to false.
|
139
139
|
# * *symbolize_names*: If set to true, returns symbols for the names
|
140
|
-
# (keys) in a JSON object. Otherwise strings are returned
|
140
|
+
# (keys) in a JSON object. Otherwise strings are returned. Strings are
|
141
141
|
# the default.
|
142
142
|
# * *create_additions*: If set to false, the Parser doesn't create
|
143
|
-
# additions even if a
|
143
|
+
# additions even if a matching class and create_id was found. This option
|
144
144
|
# defaults to true.
|
145
145
|
# * *object_class*: Defaults to Hash
|
146
146
|
# * *array_class*: Defaults to Array
|
@@ -149,19 +149,19 @@ module JSON
|
|
149
149
|
end
|
150
150
|
|
151
151
|
# Parse the JSON document _source_ into a Ruby data structure and return it.
|
152
|
-
# The bang version of the parse method
|
152
|
+
# The bang version of the parse method defaults to the more dangerous values
|
153
153
|
# for the _opts_ hash, so be sure only to parse trusted _source_ documents.
|
154
154
|
#
|
155
155
|
# _opts_ can have the following keys:
|
156
156
|
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
|
157
157
|
# structures. Enable depth checking with :max_nesting => anInteger. The parse!
|
158
|
-
# methods defaults to not doing max depth checking: This can be dangerous
|
158
|
+
# methods defaults to not doing max depth checking: This can be dangerous
|
159
159
|
# if someone wants to fill up your stack.
|
160
160
|
# * *allow_nan*: If set to true, allow NaN, Infinity, and -Infinity in
|
161
161
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
162
162
|
# to true.
|
163
163
|
# * *create_additions*: If set to false, the Parser doesn't create
|
164
|
-
# additions even if a
|
164
|
+
# additions even if a matching class and create_id was found. This option
|
165
165
|
# defaults to true.
|
166
166
|
def parse!(source, opts = {})
|
167
167
|
opts = {
|
@@ -185,10 +185,10 @@ module JSON
|
|
185
185
|
# * *indent*: a string used to indent levels (default: ''),
|
186
186
|
# * *space*: a string that is put after, a : or , delimiter (default: ''),
|
187
187
|
# * *space_before*: a string that is put before a : pair delimiter (default: ''),
|
188
|
-
# * *object_nl*: a string that is put at the end of a JSON object (default: ''),
|
188
|
+
# * *object_nl*: a string that is put at the end of a JSON object (default: ''),
|
189
189
|
# * *array_nl*: a string that is put at the end of a JSON array (default: ''),
|
190
190
|
# * *allow_nan*: true if NaN, Infinity, and -Infinity should be
|
191
|
-
# generated, otherwise an exception is thrown
|
191
|
+
# generated, otherwise an exception is thrown if these values are
|
192
192
|
# encountered. This options defaults to false.
|
193
193
|
# * *max_nesting*: The maximum depth of nesting allowed in the data
|
194
194
|
# structures from which JSON is to be generated. Disable depth checking
|
@@ -196,9 +196,13 @@ module JSON
|
|
196
196
|
#
|
197
197
|
# See also the fast_generate for the fastest creation method with the least
|
198
198
|
# amount of sanity checks, and the pretty_generate method for some
|
199
|
-
# defaults for
|
199
|
+
# defaults for pretty output.
|
200
200
|
def generate(obj, opts = nil)
|
201
|
-
|
201
|
+
if State === opts
|
202
|
+
state, opts = opts, nil
|
203
|
+
else
|
204
|
+
state = SAFE_STATE_PROTOTYPE.dup
|
205
|
+
end
|
202
206
|
if opts
|
203
207
|
if opts.respond_to? :to_hash
|
204
208
|
opts = opts.to_hash
|
@@ -223,9 +227,13 @@ module JSON
|
|
223
227
|
# This method disables the checks for circles in Ruby objects.
|
224
228
|
#
|
225
229
|
# *WARNING*: Be careful not to pass any Ruby data structures with circles as
|
226
|
-
# _obj_ argument
|
230
|
+
# _obj_ argument because this will cause JSON to go into an infinite loop.
|
227
231
|
def fast_generate(obj, opts = nil)
|
228
|
-
|
232
|
+
if State === opts
|
233
|
+
state, opts = opts, nil
|
234
|
+
else
|
235
|
+
state = FAST_STATE_PROTOTYPE.dup
|
236
|
+
end
|
229
237
|
if opts
|
230
238
|
if opts.respond_to? :to_hash
|
231
239
|
opts = opts.to_hash
|
@@ -249,10 +257,14 @@ module JSON
|
|
249
257
|
# The returned document is a prettier form of the document returned by
|
250
258
|
# #unparse.
|
251
259
|
#
|
252
|
-
# The _opts_ argument can be used to configure the generator
|
260
|
+
# The _opts_ argument can be used to configure the generator. See the
|
253
261
|
# generate method for a more detailed explanation.
|
254
262
|
def pretty_generate(obj, opts = nil)
|
255
|
-
|
263
|
+
if State === opts
|
264
|
+
state, opts = opts, nil
|
265
|
+
else
|
266
|
+
state = PRETTY_STATE_PROTOTYPE.dup
|
267
|
+
end
|
256
268
|
if opts
|
257
269
|
if opts.respond_to? :to_hash
|
258
270
|
opts = opts.to_hash
|
@@ -273,7 +285,7 @@ module JSON
|
|
273
285
|
# :startdoc:
|
274
286
|
|
275
287
|
# Load a ruby data structure from a JSON _source_ and return it. A source can
|
276
|
-
# either be a string-like object, an IO
|
288
|
+
# either be a string-like object, an IO-like object, or an object responding
|
277
289
|
# to the read method. If _proc_ was given, it will be called with any nested
|
278
290
|
# Ruby object as an argument recursively in depth first order.
|
279
291
|
#
|
@@ -291,7 +303,7 @@ module JSON
|
|
291
303
|
recurse_proc(result, &proc) if proc
|
292
304
|
result
|
293
305
|
end
|
294
|
-
|
306
|
+
|
295
307
|
# Recursively calls passed _Proc_ if the parsed data structure is an _Array_ or _Hash_
|
296
308
|
def recurse_proc(result, &proc)
|
297
309
|
case result
|
@@ -312,10 +324,10 @@ module JSON
|
|
312
324
|
# Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns
|
313
325
|
# the result.
|
314
326
|
#
|
315
|
-
# If anIO (an IO
|
327
|
+
# If anIO (an IO-like object or an object that responds to the write method)
|
316
328
|
# was given, the resulting JSON is written to it.
|
317
329
|
#
|
318
|
-
# If the number of nested arrays or objects exceeds _limit_ an ArgumentError
|
330
|
+
# If the number of nested arrays or objects exceeds _limit_, an ArgumentError
|
319
331
|
# exception is raised. This argument is similar (but not exactly the
|
320
332
|
# same!) to the _limit_ argument in Marshal.dump.
|
321
333
|
#
|
@@ -360,7 +372,7 @@ module JSON
|
|
360
372
|
require 'iconv'
|
361
373
|
# Encodes string using _iconv_ library
|
362
374
|
def self.iconv(to, from, string)
|
363
|
-
Iconv.
|
375
|
+
Iconv.conv(to, from, string)
|
364
376
|
end
|
365
377
|
end
|
366
378
|
|
@@ -396,11 +408,11 @@ module ::Kernel
|
|
396
408
|
nil
|
397
409
|
end
|
398
410
|
|
399
|
-
# If _object_ is string-like parse the string and return the parsed result as
|
400
|
-
# a Ruby data structure. Otherwise generate a JSON text from the Ruby data
|
411
|
+
# If _object_ is string-like, parse the string and return the parsed result as
|
412
|
+
# a Ruby data structure. Otherwise, generate a JSON text from the Ruby data
|
401
413
|
# structure object and return it.
|
402
414
|
#
|
403
|
-
# The _opts_ argument is passed through to generate/parse respectively
|
415
|
+
# The _opts_ argument is passed through to generate/parse respectively. See
|
404
416
|
# generate and parse for their documentation.
|
405
417
|
def JSON(object, *args)
|
406
418
|
if object.respond_to? :to_str
|
@@ -413,10 +425,10 @@ end
|
|
413
425
|
|
414
426
|
# Extends any Class to include _json_creatable?_ method.
|
415
427
|
class ::Class
|
416
|
-
# Returns true
|
428
|
+
# Returns true if this class can be used to create an instance
|
417
429
|
# from a serialised JSON string. The class has to implement a class
|
418
|
-
# method _json_create_ that expects a hash as first parameter
|
419
|
-
# the required data.
|
430
|
+
# method _json_create_ that expects a hash as first parameter. The hash
|
431
|
+
# should include the required data.
|
420
432
|
def json_creatable?
|
421
433
|
respond_to?(:json_create)
|
422
434
|
end
|