summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2010-03-13 21:11:58 +0100
committerFlorian Frank <flori@ping.de>2010-03-13 21:11:58 +0100
commitc3e8dd92f04b010366e4d7152c83c7486af93e1e (patch)
tree883b600b03e7a5788f50fe4f71b4fe9f88f7ef9f /lib
parent92b013ce8e0a5c3caefd15f450409ed69aa539f2 (diff)
parent3db50701a4a71e49709c63483d2ba4b5a408373b (diff)
downloadjson-c3e8dd92f04b010366e4d7152c83c7486af93e1e.tar.gz
Merge commit 'v1.2.3'
Merged in some additional features from the v1.2 branch.
Diffstat (limited to 'lib')
-rw-r--r--lib/json/common.rb5
-rw-r--r--lib/json/pure/generator.rb7
-rw-r--r--lib/json/pure/parser.rb6
3 files changed, 16 insertions, 2 deletions
diff --git a/lib/json/common.rb b/lib/json/common.rb
index c0b35e2..cd9d1c6 100644
--- a/lib/json/common.rb
+++ b/lib/json/common.rb
@@ -130,9 +130,14 @@ module JSON
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
# to false.
+ # * *symbolize_names*: If set to true, returns symbols for the names
+ # (keys) in a JSON object. Otherwise strings are returned, which is also
+ # the default.
# * *create_additions*: If set to false, the Parser doesn't create
# additions even if a matchin class and create_id was found. This option
# defaults to true.
+ # * *object_class*: Defaults to Hash
+ # * *array_class*: Defaults to Array
def parse(source, opts = {})
Parser.new(source, opts).parse
end
diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb
index a656768..0584108 100644
--- a/lib/json/pure/generator.rb
+++ b/lib/json/pure/generator.rb
@@ -173,7 +173,7 @@ module JSON
# Returns true, if circular data structures are checked,
# otherwise returns false.
def check_circular?
- !!@max_nesting.zero?
+ !@max_nesting.zero?
end
# Returns true if NaN, Infinity, and -Infinity should be considered as
@@ -226,6 +226,11 @@ module JSON
end
result
end
+
+ # Return the value returned by method +name+.
+ def [](name)
+ __send__ name
+ end
end
module GeneratorMethods
diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb
index 7a09f2f..f6de8d1 100644
--- a/lib/json/pure/parser.rb
+++ b/lib/json/pure/parser.rb
@@ -60,6 +60,9 @@ module JSON
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
# to false.
+ # * *symbolize_names*: If set to true, returns symbols for the names
+ # (keys) in a JSON object. Otherwise strings are returned, which is also
+ # the default.
# * *create_additions*: If set to false, the Parser doesn't create
# additions even if a matchin class and create_id was found. This option
# defaults to true.
@@ -109,6 +112,7 @@ module JSON
@max_nesting = 0
end
@allow_nan = !!opts[:allow_nan]
+ @symbolize_names = !!opts[:symbolize_names]
ca = true
ca = opts[:create_additions] if opts.key?(:create_additions)
@create_id = ca ? JSON.create_id : nil
@@ -267,7 +271,7 @@ module JSON
end
skip(IGNORE)
unless (value = parse_value).equal? UNPARSED
- result[string] = value
+ result[@symbolize_names ? string.to_sym : string] = value
delim = false
skip(IGNORE)
if scan(COLLECTION_DELIMITER)