Struct justjson::parser::ParseConfig
source · #[non_exhaustive]pub struct ParseConfig {
pub allow_trailing_commas: bool,
pub recursion_limit: Option<usize>,
pub allow_all_types_at_root: bool,
}
Expand description
A JSON Value parsing configuration.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.allow_trailing_commas: bool
If true, allows trailing commas when parsing arrays and objects. If
false, trailing commas will cause an ErrorKind::IllegalTrailingComma
to be returned.
recursion_limit: Option<usize>
If present, nested arrays and objects will be limited to
recursion_limit
levels of nesting. If not present, no checks will be
performed which can cause a stack overflow with very deeply nested
payloads.
allow_all_types_at_root: bool
If true, only arrays or objects will be allowed to parse at the root of the JSON payload.
Implementations§
source§impl ParseConfig
impl ParseConfig
sourcepub const fn new() -> Self
pub const fn new() -> Self
Returns the default configuration:
let config = justjson::parser::ParseConfig::new();
assert_eq!(config.allow_trailing_commas, false);
assert_eq!(config.recursion_limit, Some(128));
assert_eq!(config.allow_all_types_at_root, true);
sourcepub const fn strict() -> Self
pub const fn strict() -> Self
Returns a strict configuration, which differs from the default configuration by only allowing objects and arrays at the root:
let config = justjson::parser::ParseConfig::strict();
assert_eq!(config.allow_trailing_commas, false);
assert_eq!(config.recursion_limit, Some(128));
assert_eq!(config.allow_all_types_at_root, false);
sourcepub const fn without_recursion_limit(self) -> Self
pub const fn without_recursion_limit(self) -> Self
Disables recursuion limit testing.
Note: Malicious payloads may be able to cause stack overflows to occur if this is disabled.
sourcepub const fn with_recursion_limit(self, limit: usize) -> Self
pub const fn with_recursion_limit(self, limit: usize) -> Self
Sets the maximum recursion limit to limit
.
sourcepub const fn allowing_all_types_at_root(self, allow_all: bool) -> Self
pub const fn allowing_all_types_at_root(self, allow_all: bool) -> Self
Sets whether to allow all types at the root of the JSON payload. If false, only arrays and objects will be allowed at the root of the JSON payload.
sourcepub const fn allowing_trailing_commas(self) -> Self
pub const fn allowing_trailing_commas(self) -> Self
Allows trailing commas when parsing objects and arrays.
use justjson::parser::ParseConfig;
use justjson::Value;
let source = r#"{"a":[true,],}"#;
Value::from_json(source).expect_err("not enabled by default");
let config = ParseConfig::new().allowing_trailing_commas();
Value::from_json_with_config(source, config).expect("now parses");
Trait Implementations§
source§impl Clone for ParseConfig
impl Clone for ParseConfig
source§fn clone(&self) -> ParseConfig
fn clone(&self) -> ParseConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ParseConfig
impl Debug for ParseConfig
source§impl Default for ParseConfig
impl Default for ParseConfig
source§impl PartialEq for ParseConfig
impl PartialEq for ParseConfig
source§fn eq(&self, other: &ParseConfig) -> bool
fn eq(&self, other: &ParseConfig) -> bool
self
and other
values to be equal, and is used
by ==
.