aboutsummaryrefslogtreecommitdiffstats
path: root/lib/json/common.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/json/common.rb')
-rw-r--r--lib/json/common.rb18
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.