| Crates.io | serde_json_diagnostics |
| lib.rs | serde_json_diagnostics |
| version | 0.1.0 |
| created_at | 2026-01-20 12:10:17.300031+00 |
| updated_at | 2026-01-20 12:10:17.300031+00 |
| description | Enhanced deserialization error diagnostics for serde_json with accurate JSON path tracking |
| homepage | |
| repository | https://github.com/pyk/serde-json-diagnostics |
| max_upload_size | |
| id | 2056458 |
| size | 183,887 |
A serde_json extension for better deserialization error diagnostics with accurate JSON path tracking.
This crate provides drop-in replacements for serde_json::from_str,
serde_json::from_slice, and serde_json::from_reader that return enhanced
errors with JSON path information. The path tracking helps you quickly identify
where in your JSON structure a deserialization error occurred.
Current Status: Phase 1 complete - API is functional and ready for use. Path tracking implementation is pending and will be added in a future update.
Add this to your Cargo.toml:
[dependencies]
serde_json_diagnostics = "0.1.0"
Replace your serde_json deserialization calls with the equivalents from this
crate:
use serde::Deserialize;
use serde_json_diagnostics::from_str;
#[derive(Deserialize)]
struct User {
name: String,
age: u32,
}
fn main() -> Result<(), serde_json_diagnostics::ErrorDiagnostic> {
let json = r#"{"name": "Alice", "age": 30}"#;
let user: User = from_str(json)?;
println!("User: {} is {} years old", user.name, user.age);
Ok(())
}
The crate provides three functions with the same signatures as serde_json:
from_str<'a, T>(s: &'a str) -> Result<T> - Deserialize from a JSON stringfrom_slice<'a, T>(bytes: &'a [u8]) -> Result<T> - Deserialize from a byte
slicefrom_reader<R, T>(reader: R) -> Result<T> - Deserialize from an IO readerAll functions return Result<T, ErrorDiagnostic> instead of
Result<T, serde_json::Error>.
use serde::Deserialize;
use serde_json_diagnostics::from_str;
#[derive(Deserialize)]
struct Config {
debug: bool,
port: u16,
}
let json = r#"{"debug": true, "port": "invalid"}"#;
match from_str::<Config>(json) {
Ok(config) => println!("Loaded config: {:?}", config),
Err(e) => eprintln!("Failed to parse JSON: {}", e),
}
serde_json::from_str, from_slice, and
from_readerErrorDiagnostic) that wraps serde_json::ErrorThe standard serde_path_to_error crate has
known issues with path
tracking for certain enum representations (internally tagged, adjacently tagged,
and untagged enums). This crate aims to provide more reliable path tracking
using breadcrumb-style navigation, while maintaining the same ergonomic API as
serde_json.
Credits to @BrokenStandards.
MIT License.