Skip to main content

FromJsonConfig

Struct FromJsonConfig 

Source
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: String

Default 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: SurrogatePolicy

Policy 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: bool

Enable 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

Source

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

Source§

fn clone(&self) -> FromJsonConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FromJsonConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FromJsonConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl ImportConfig for FromJsonConfig

Source§

fn default_type_name(&self) -> &str

Get the default type name for collections without explicit metadata.
Source§

fn version(&self) -> (u32, u32)

Get the HEDL version to use for the imported document.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more