pub struct LenientJsonDecoder { /* private fields */ }Expand description
A configurable JSON decoder for non-fully-trusted text inputs.
LenientJsonDecoder applies a small set of predictable normalization rules
before delegating actual parsing and deserialization to serde_json.
Implementations§
Source§impl LenientJsonDecoder
impl LenientJsonDecoder
Sourcepub const fn new(options: JsonDecodeOptions) -> Self
pub const fn new(options: JsonDecodeOptions) -> Self
Sourcepub const fn options(&self) -> &JsonDecodeOptions
pub const fn options(&self) -> &JsonDecodeOptions
Returns the immutable options used by this decoder.
§Returns
The option set supplied when the decoder was created.
Sourcepub fn decode<T>(&self, input: &str) -> Result<T, JsonDecodeError>where
T: DeserializeOwned,
pub fn decode<T>(&self, input: &str) -> Result<T, JsonDecodeError>where
T: DeserializeOwned,
Decodes input into the target Rust type T without a top-level
structure constraint.
§Parameters
input- Raw JSON text to normalize and deserialize.
§Returns
The deserialized target value.
§Errors
Returns JsonDecodeError when input normalization, JSON parsing, or
target deserialization fails.
§Panics
Panics when the serde::Deserialize implementation for T panics.
Sourcepub fn decode_slice<T>(&self, input: &[u8]) -> Result<T, JsonDecodeError>where
T: DeserializeOwned,
pub fn decode_slice<T>(&self, input: &[u8]) -> Result<T, JsonDecodeError>where
T: DeserializeOwned,
Decodes UTF-8 input bytes into the target Rust type.
The configured raw byte limit is enforced before UTF-8 validation. Valid UTF-8 is borrowed and delegated to the string decoder.
§Parameters
input- Raw JSON bytes to validate, normalize, and deserialize.
§Returns
The deserialized target value.
§Errors
Returns a JSON decode error when the raw byte limit is exceeded, the bytes are not valid UTF-8, or subsequent JSON decoding fails.
§Panics
Panics when the serde::Deserialize implementation for T panics.
Sourcepub fn decode_object<T>(&self, input: &str) -> Result<T, JsonDecodeError>where
T: DeserializeOwned,
pub fn decode_object<T>(&self, input: &str) -> Result<T, JsonDecodeError>where
T: DeserializeOwned,
Decodes input into T, requiring a top-level JSON object.
The target is deserialized directly from normalized text after a top-level check, preserving serde’s duplicate-field and number handling semantics.
§Parameters
input- Raw JSON text to normalize and deserialize.
§Returns
The deserialized target value when the normalized input is a JSON object.
§Errors
Returns JsonDecodeError when normalization or parsing fails, when
the top-level value is not an object, or when the object cannot be
deserialized into T.
§Panics
Panics when the serde::Deserialize implementation for T panics.
Sourcepub fn decode_array<T>(&self, input: &str) -> Result<Vec<T>, JsonDecodeError>where
T: DeserializeOwned,
pub fn decode_array<T>(&self, input: &str) -> Result<Vec<T>, JsonDecodeError>where
T: DeserializeOwned,
Decodes input into Vec<T>, requiring a top-level JSON array.
The elements are deserialized directly from normalized text after a top-level check.
§Parameters
input- Raw JSON text to normalize and deserialize.
§Returns
The deserialized elements when the normalized input is a JSON array.
§Errors
Returns JsonDecodeError when normalization or parsing fails, when
the top-level value is not an array, or when an element cannot be
deserialized into T.
§Panics
Panics when the serde::Deserialize implementation for T panics.
Sourcepub fn decode_value(&self, input: &str) -> Result<Value, JsonDecodeError>
pub fn decode_value(&self, input: &str) -> Result<Value, JsonDecodeError>
Decodes input into a serde_json::Value.
This entry point intentionally constructs a JSON DOM because its public
return type is Value.
§Parameters
input- Raw JSON text to normalize and parse.
§Returns
The parsed dynamic JSON value.
§Errors
Returns JsonDecodeError when input normalization or JSON parsing
fails.
Trait Implementations§
Source§impl Clone for LenientJsonDecoder
impl Clone for LenientJsonDecoder
Source§fn clone(&self) -> LenientJsonDecoder
fn clone(&self) -> LenientJsonDecoder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more