diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/json/common.rb | 5 | ||||
-rw-r--r-- | lib/json/pure/parser.rb | 6 | ||||
-rw-r--r-- | lib/json/version.rb | 2 |
3 files changed, 11 insertions, 2 deletions
diff --git a/lib/json/common.rb b/lib/json/common.rb index 39f6336..2f1584e 100644 --- a/lib/json/common.rb +++ b/lib/json/common.rb @@ -116,9 +116,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 = {}) JSON.parser.new(source, opts).parse end 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) diff --git a/lib/json/version.rb b/lib/json/version.rb index ff48b9b..c0fd7e0 100644 --- a/lib/json/version.rb +++ b/lib/json/version.rb @@ -1,6 +1,6 @@ module JSON # JSON version - VERSION = '1.2.0' + VERSION = '1.2.1' VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc: VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc: VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: |