mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
6d2dee14f3
commit
b60d64b001
7 changed files with 51 additions and 22 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue