diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-06 22:38:42 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-06 22:38:42 +0000 |
commit | b60d64b001c8819e6626b00efbeae96560368a08 (patch) | |
tree | 5f4596a1a68c41d917a4aacb43b9804c2121158b /lib/json/common.rb | |
parent | 6d2dee14f3d5d4224effd0ec2d8fbc07dc54cbac (diff) | |
download | ruby-b60d64b001c8819e6626b00efbeae96560368a08.tar.gz |
* lib/json/common.rb: Ponder offering parse\! method.
* lib/json/editor.rb: be a bit more robust while loading data.
* ext/json/ext/{generator,parser}/extconf.rb:
add a have_header directive for st.h
* test/json: fix some tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/json/common.rb')
-rw-r--r-- | lib/json/common.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/json/common.rb b/lib/json/common.rb index c820cfbcce..0967aed8c2 100644 --- a/lib/json/common.rb +++ b/lib/json/common.rb @@ -101,11 +101,27 @@ module JSON # _opts_ can have the following # keys: # * *max_nesting*: The maximum depth of nesting allowed in the parsed data - # structures. Disable depth checking with :max_nesting => false. + # structures. Disable depth checking with :max_nesting => false. This value + # defaults to 19. def parse(source, opts = {}) JSON.parser.new(source, opts).parse end + # Parse the JSON string _source_ into a Ruby data structure and return it. + # + # _opts_ can have the following + # keys: + # * *max_nesting*: The maximum depth of nesting allowed in the parsed data + # structures. Enable depth checking with :max_nesting => anInteger. The parse! + # methods defaults to not doing max depth checking: This can be dangerous, + # if someone wants to fill up your stack. + def parse!(source, opts = {}) + opts = { + :max_nesting => false + }.update(opts) + JSON.parser.new(source, opts).parse + end + # Unparse the Ruby data structure _obj_ into a single line JSON string and # return it. _state_ is a JSON::State object, that can be used to configure # the output further. |