serde_json_diagnostics/
lib.rs

1//! A serde_json extension for better deserialization error diagnostics with
2//! accurate path tracking.
3//!
4//! This crate provides drop-in replacements for `serde_json::from_str`,
5//! `serde_json::from_slice`, and `serde_json::from_reader` that return enhanced
6//! errors with JSON path information.
7//!
8//! # Current Status
9//!
10//! Path tracking implementation is pending completion in Phase 4. Currently,
11//! the API wraps serde_json functions and returns ErrorDiagnostic type, but
12//! path information is not yet captured.
13
14pub use de::{from_reader, from_slice, from_str};
15pub use error::{ErrorDiagnostic, Result};
16
17mod de;
18mod error;
19mod path;
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24
25    #[test]
26    fn result_type_alias() {
27        let json = r#"42"#;
28        let result: Result<i32> = from_str(json);
29        assert!(result.is_ok());
30        assert_eq!(result.unwrap(), 42);
31    }
32
33    #[test]
34    fn error_diagnostic_is_send_and_sync() {
35        fn assert_send_sync<T: Send + Sync>() {}
36
37        let json = r#"{}"#;
38        let result: Result<serde_json::Value> = from_str(json);
39        assert!(result.is_ok());
40
41        assert_send_sync::<ErrorDiagnostic>();
42    }
43
44    #[test]
45    fn error_diagnostic_display() {
46        let json = r#"invalid json"#;
47        let result: Result<serde_json::Value> = from_str(json);
48        assert!(result.is_err());
49
50        let error = result.unwrap_err();
51        let error_string = format!("{}", error);
52        assert!(!error_string.is_empty());
53    }
54}
55