serde_json_diagnostics 0.1.0

Enhanced deserialization error diagnostics for serde_json with accurate JSON path tracking
Documentation
//! A serde_json extension for better deserialization error diagnostics with
//! accurate 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.
//!
//! # Current Status
//!
//! Path tracking implementation is pending completion in Phase 4. Currently,
//! the API wraps serde_json functions and returns ErrorDiagnostic type, but
//! path information is not yet captured.

pub use de::{from_reader, from_slice, from_str};
pub use error::{ErrorDiagnostic, Result};

mod de;
mod error;
mod path;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn result_type_alias() {
        let json = r#"42"#;
        let result: Result<i32> = from_str(json);
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), 42);
    }

    #[test]
    fn error_diagnostic_is_send_and_sync() {
        fn assert_send_sync<T: Send + Sync>() {}

        let json = r#"{}"#;
        let result: Result<serde_json::Value> = from_str(json);
        assert!(result.is_ok());

        assert_send_sync::<ErrorDiagnostic>();
    }

    #[test]
    fn error_diagnostic_display() {
        let json = r#"invalid json"#;
        let result: Result<serde_json::Value> = from_str(json);
        assert!(result.is_err());

        let error = result.unwrap_err();
        let error_string = format!("{}", error);
        assert!(!error_string.is_empty());
    }
}