pub struct FromJsonConfigBuilder { /* private fields */ }Expand description
Builder for FromJsonConfig
Provides ergonomic configuration of JSON import limits and behavior.
§Examples
use hedl_json::FromJsonConfig;
// Custom limits
let config = FromJsonConfig::builder()
.max_depth(1_000)
.max_array_size(100_000)
.max_string_length(10 * 1024 * 1024)
.build();
// Strict limits for untrusted input
let strict = FromJsonConfig::builder()
.max_depth(50)
.max_array_size(10_000)
.max_string_length(1_000_000)
.max_object_size(1_000)
.build();
// Unlimited (use with caution!)
let unlimited = FromJsonConfig::builder()
.unlimited()
.build();Implementations§
Source§impl FromJsonConfigBuilder
impl FromJsonConfigBuilder
Sourcepub fn default_type_name(self, name: impl Into<String>) -> Self
pub fn default_type_name(self, name: impl Into<String>) -> Self
Set the default type name for arrays without metadata
Sourcepub fn max_depth(self, limit: usize) -> Self
pub fn max_depth(self, limit: usize) -> Self
Set the maximum recursion depth
Use None to disable the limit (not recommended for untrusted input).
Sourcepub fn max_array_size(self, limit: usize) -> Self
pub fn max_array_size(self, limit: usize) -> Self
Set the maximum array size
Use None to disable the limit (not recommended for untrusted input).
Sourcepub fn max_string_length(self, limit: usize) -> Self
pub fn max_string_length(self, limit: usize) -> Self
Set the maximum string length in bytes
Use None to disable the limit (not recommended for untrusted input).
Sourcepub fn max_object_size(self, limit: usize) -> Self
pub fn max_object_size(self, limit: usize) -> Self
Set the maximum object size (number of keys)
Use None to disable the limit (not recommended for untrusted input).
Sourcepub fn surrogate_policy(self, policy: SurrogatePolicy) -> Self
pub fn surrogate_policy(self, policy: SurrogatePolicy) -> Self
Set the policy for handling unpaired UTF-16 surrogates
§Options
SurrogatePolicy::Reject(default): Error on invalid surrogatesSurrogatePolicy::ReplaceWithFFFD: Replace with U+FFFDSurrogatePolicy::Skip: Remove invalid surrogates silently
§Example
use hedl_json::{FromJsonConfig, SurrogatePolicy};
let config = FromJsonConfig::builder()
.surrogate_policy(SurrogatePolicy::ReplaceWithFFFD)
.build();Sourcepub fn unlimited(self) -> Self
pub fn unlimited(self) -> Self
Disable all limits (use with caution - only for trusted input)
This removes all safety limits and can lead to memory exhaustion or stack overflow with malicious or malformed JSON.
Sourcepub fn lenient(self, lenient: bool) -> Self
pub fn lenient(self, lenient: bool) -> Self
Enable lenient JSON parsing (trailing commas, comments)
When enabled, the parser accepts:
- Trailing commas in arrays and objects
- Single-line (//) and multi-line (/* */) comments
Requires the lenient feature flag.
§Examples
use hedl_json::FromJsonConfig;
let config = FromJsonConfig::builder()
.lenient(true)
.build();
// Now you can parse JSON with trailing commas
let json = r#"{"name": "Alice", "age": 30,}"#;Sourcepub fn build(self) -> FromJsonConfig
pub fn build(self) -> FromJsonConfig
Build the configuration
Trait Implementations§
Source§impl Clone for FromJsonConfigBuilder
impl Clone for FromJsonConfigBuilder
Source§fn clone(&self) -> FromJsonConfigBuilder
fn clone(&self) -> FromJsonConfigBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more