Class: JSON::Ext::ParserConfig
- Inherits:
-
Object
- Object
- JSON::Ext::ParserConfig
- Defined in:
- ext/json/ext/parser/parser.c
Instance Method Summary collapse
-
#new(opts) ⇒ Object
constructor
Creates a new JSON::Ext::ParserConfig instance.
-
#parse(source) ⇒ Object
Parses the current JSON text source and returns the complete data structure as a result.
Constructor Details
#new(opts) ⇒ Object
Creates a new JSON::Ext::ParserConfig instance.
It will be configured by the opts hash. opts can have the following keys:
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|nil|0, it defaults to 100.
-
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. It’s not possible to use this option in conjunction with the create_additions option.
-
create_additions: If set to false, the Parser doesn’t create additions even if a matching class and create_id was found. This option defaults to false.
-
object_class: Defaults to Hash. If another type is provided, it will be used instead of Hash to represent JSON objects. The type must respond to
newwithout arguments, and return an object that respond to[]=. -
array_class: Defaults to Array If another type is provided, it will be used instead of Hash to represent JSON arrays. The type must respond to
newwithout arguments, and return an object that respond to <<. -
decimal_class: Specifies which class to use instead of the default
(Float) when parsing decimal numbers. This class must accept a single string argument in its constructor.
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 |
# File 'ext/json/ext/parser/parser.c', line 1309
static VALUE cParserConfig_initialize(VALUE self, VALUE opts)
{
GET_PARSER_CONFIG;
parser_config_init(config, opts);
RB_OBJ_WRITTEN(self, Qundef, config->create_id);
RB_OBJ_WRITTEN(self, Qundef, config->object_class);
RB_OBJ_WRITTEN(self, Qundef, config->array_class);
RB_OBJ_WRITTEN(self, Qundef, config->decimal_class);
RB_OBJ_WRITTEN(self, Qundef, config->match_string);
return self;
}
|
Instance Method Details
#parse(source) ⇒ Object
Parses the current JSON text source and returns the complete data
structure as a result.
It raises JSON::ParserError if fail to parse.
1361 1362 1363 1364 1365 |
# File 'ext/json/ext/parser/parser.c', line 1361
static VALUE cParserConfig_parse(VALUE self, VALUE Vsource)
{
GET_PARSER_CONFIG;
return cParser_parse(config, Vsource);
}
|