Skip to main content

Crate qubit_json

Crate qubit_json 

Source
Expand description

Provides the public API for the qubit-json crate.

The crate exposes a lenient JSON decoder and the related option and error types needed to normalize and deserialize JSON text from non-fully-trusted sources.

§Quick start

use qubit_json::{JsonDecodeOptions, LenientJsonDecoder};

let decoder = LenientJsonDecoder::new(
    JsonDecodeOptions::default().with_max_input_bytes(Some(1024)),
);
let value = decoder.decode_value("```json\n{\"ok\":true}\n```")?;

assert_eq!(value["ok"], true);

§Error privacy

Errors are redacted by default: input-derived serde messages and values are excluded from the message, debug representation, and standard error source. Safe structural metadata, including parser locations and UTF-8 failure offsets, remains available. Detailed diagnostics must be enabled explicitly and may expose input values.

use qubit_json::{
    ErrorPrivacyPolicy,
    JsonDecodeOptions,
    LenientJsonDecoder,
};

let redacted = LenientJsonDecoder::default()
    .decode::<u64>(r#""TOP_SECRET""#)
    .expect_err("a JSON string cannot deserialize into u64");
assert_eq!(redacted.privacy_policy(), ErrorPrivacyPolicy::Redacted);
assert!(!redacted.to_string().contains("TOP_SECRET"));
assert!(std::error::Error::source(&redacted).is_none());

let detailed = LenientJsonDecoder::new(
    JsonDecodeOptions::default()
        .with_error_privacy_policy(ErrorPrivacyPolicy::Detailed),
)
.decode::<u64>(r#""TOP_SECRET""#)
.expect_err("a JSON string cannot deserialize into u64");
assert_eq!(detailed.privacy_policy(), ErrorPrivacyPolicy::Detailed);
assert!(std::error::Error::source(&detailed).is_some());

§Must-use configuration values

#![deny(unused_must_use)]
qubit_json::JsonDecodeOptions::default();
#![deny(unused_must_use)]
qubit_json::LenientJsonDecoder::default();

Structs§

JsonDecodeError
Error returned when lenient JSON decoding fails.
JsonDecodeOptions
Configuration switches for crate::LenientJsonDecoder.
LenientJsonDecoder
A configurable JSON decoder for non-fully-trusted text inputs.

Enums§

ErrorPrivacyPolicy
Controls whether JSON decoding errors retain input-derived serde details.
JsonDecodeErrorKind
Represents the coarse category of a lenient JSON decoding failure.
JsonDecodeStage
Identifies the decoding stage where an error was produced.
JsonTopLevelKind
Represents the top-level kind of a parsed JSON value.
MarkdownFenceClosing
Specifies whether an opening Markdown code fence needs a closing fence.
MarkdownFencePolicy
Controls whether and how one outer Markdown code fence is stripped.