pub struct JsonDecodeOptions {
pub trim_whitespace: bool,
pub strip_utf8_bom: bool,
pub strip_markdown_code_fence: bool,
pub strip_markdown_code_fence_requires_closing: bool,
pub strip_markdown_code_fence_json_only: bool,
pub escape_control_chars_in_strings: bool,
pub max_input_bytes: Option<usize>,
}Expand description
Configuration switches for crate::LenientJsonDecoder.
Each flag controls one normalization rule applied before parsing JSON. Defaults are intentionally conservative and cover the most common non-fully-trusted text inputs without attempting aggressive repair.
Fields§
§trim_whitespace: boolControls whether leading and trailing whitespace is removed before any other normalization step is applied.
strip_utf8_bom: boolControls whether a leading UTF-8 byte order mark (U+FEFF) is removed
before parsing.
strip_markdown_code_fence: boolControls whether one outer Markdown code fence is removed.
Typical examples include json ... and bare fenced blocks
starting with ````` followed by a newline.
strip_markdown_code_fence_requires_closing: boolControls whether Markdown fence stripping requires a matching closing fence.
When enabled, an opening fence without a valid closing fence keeps the input unchanged.
strip_markdown_code_fence_json_only: boolControls whether Markdown fence stripping only accepts JSON-like info
strings whose first token is empty, json, or jsonc.
When enabled, fenced blocks labeled with other languages are not stripped.
escape_control_chars_in_strings: boolControls whether raw ASCII control characters inside JSON string literals are converted into valid JSON escape sequences.
max_input_bytes: Option<usize>Caps the accepted raw input size in bytes before normalization.
When set to Some(limit), any input whose byte length is greater than
limit is rejected before further processing. When set to None,
no size limit is enforced.
Implementations§
Source§impl JsonDecodeOptions
impl JsonDecodeOptions
Sourcepub const fn lenient() -> Self
pub const fn lenient() -> Self
Creates the default lenient option set.
This preset enables the small, predictable normalization rules intended for non-fully-trusted text inputs while keeping aggressive JSON repair out of scope.
Sourcepub const fn strict() -> Self
pub const fn strict() -> Self
Creates an option set that disables all normalization rules.
This preset still allows serde_json to accept JSON syntax that is valid
on its own, but the decoder will not trim, strip BOMs, remove Markdown
fences, or escape raw control characters before parsing.
Sourcepub const fn json_code_fences_only() -> Self
pub const fn json_code_fences_only() -> Self
Creates lenient options that only strip JSON-like Markdown code fences.
The resulting preset keeps the other default normalization rules, but
restricts Markdown fence stripping to empty, json, or jsonc as the
first info-string token.
Sourcepub const fn with_max_input_bytes(self, max_input_bytes: usize) -> Self
pub const fn with_max_input_bytes(self, max_input_bytes: usize) -> Self
Returns a copy of these options with a raw input byte-size limit.
Inputs whose byte length is greater than max_input_bytes are rejected
before normalization.
Trait Implementations§
Source§impl Clone for JsonDecodeOptions
impl Clone for JsonDecodeOptions
Source§fn clone(&self) -> JsonDecodeOptions
fn clone(&self) -> JsonDecodeOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more