pub struct FromJsonConfig {
pub default_type_name: String,
pub version: (u32, u32),
pub max_depth: Option<usize>,
pub max_array_size: Option<usize>,
pub max_string_length: Option<usize>,
pub max_object_size: Option<usize>,
pub surrogate_policy: SurrogatePolicy,
pub lenient: bool,
}Expand description
Configuration for JSON import
Controls how JSON is converted to HEDL, including security limits to prevent denial-of-service attacks from malicious inputs.
§High Default Limits
The default limits are set intentionally high to handle large-scale data processing scenarios common in ML/AI applications:
- 10,000 depth: Deep nesting in complex hierarchical data
- 10,000,000 array size: Large datasets and batches
- 100 MB string length: Base64-encoded binary data, embeddings
- 100,000 object size: Rich metadata and configuration objects
These defaults prioritize functionality over restrictiveness. For untrusted input, consider using the builder pattern with custom limits.
§Examples
use hedl_json::FromJsonConfig;
// Default configuration with high limits for ML/data workloads
let config = FromJsonConfig::default();
// Custom configuration using builder pattern
let custom_config = FromJsonConfig::builder()
.max_depth(1_000)
.max_array_size(100_000)
.max_string_length(10 * 1024 * 1024) // 10 MB
.build();
// Strict configuration for untrusted input
let strict_config = FromJsonConfig::builder()
.max_depth(50)
.max_array_size(10_000)
.max_string_length(1_000_000)
.max_object_size(1_000)
.build();
// Unlimited configuration (use with caution)
let unlimited_config = FromJsonConfig::builder()
.unlimited()
.build();Fields§
§default_type_name: StringDefault type name for arrays without metadata
version: (u32, u32)HEDL version to use
max_depth: Option<usize>Maximum recursion depth (default: 10,000)
Prevents stack overflow from deeply nested JSON structures.
Set to None to disable (not recommended for untrusted input).
max_array_size: Option<usize>Maximum array size (default: 10,000,000)
Prevents memory exhaustion from extremely large arrays.
JSON arrays can contain large datasets, batches, or embeddings.
Set to None to disable (not recommended for untrusted input).
max_string_length: Option<usize>Maximum string length (default: 100 MB)
Prevents memory exhaustion from extremely large strings.
JSON strings often contain base64-encoded binary data, large
text fields, or embedded documents requiring high limits.
Set to None to disable (not recommended for untrusted input).
max_object_size: Option<usize>Maximum object size (default: 100,000)
Prevents memory exhaustion from objects with many keys.
Configuration files and metadata-rich objects can have many properties.
Set to None to disable (not recommended for untrusted input).
surrogate_policy: SurrogatePolicyPolicy for handling unpaired UTF-16 surrogates
Some systems emit JSON with unpaired surrogates (e.g., truncated JavaScript strings). This setting controls how to handle them.
Default: SurrogatePolicy::Reject (strict validation)
lenient: boolEnable lenient JSON parsing (JSON5-style trailing commas and comments)
When enabled, the parser accepts:
- Trailing commas in arrays and objects
- Single-line (//) and multi-line (/* */) comments
Requires the lenient feature flag.
Default: false (strict RFC 8259 JSON)
Implementations§
Source§impl FromJsonConfig
impl FromJsonConfig
Sourcepub fn builder() -> FromJsonConfigBuilder
pub fn builder() -> FromJsonConfigBuilder
Create a new builder for configuring JSON import
§Examples
use hedl_json::FromJsonConfig;
let config = FromJsonConfig::builder()
.max_depth(1_000)
.max_array_size(100_000)
.build();Trait Implementations§
Source§impl Clone for FromJsonConfig
impl Clone for FromJsonConfig
Source§fn clone(&self) -> FromJsonConfig
fn clone(&self) -> FromJsonConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more