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§
- Json
Decode Error - Error returned when lenient JSON decoding fails.
- Json
Decode Options - Configuration switches for
crate::LenientJsonDecoder. - Lenient
Json Decoder - A configurable JSON decoder for non-fully-trusted text inputs.
Enums§
- Error
Privacy Policy - Controls whether JSON decoding errors retain input-derived serde details.
- Json
Decode Error Kind - Represents the coarse category of a lenient JSON decoding failure.
- Json
Decode Stage - Identifies the decoding stage where an error was produced.
- Json
TopLevel Kind - Represents the top-level kind of a parsed JSON value.
- Markdown
Fence Closing - Specifies whether an opening Markdown code fence needs a closing fence.
- Markdown
Fence Policy - Controls whether and how one outer Markdown code fence is stripped.