pub struct JsonishParser { /* private fields */ }Expand description
Three-phase JSON parser for malformed LLM outputs.
§Phases
- Strip & Fix: Quick string transformations
- Standard Parse: Attempt
serde_json::from_str(fast path) - Lenient Parse: State machine for incomplete/malformed JSON
§Example
use simple_agents_healing::parser::JsonishParser;
let parser = JsonishParser::new();
let result = parser.parse(r#"{"key": "value",}"#).unwrap();
assert!(result.flags.iter().any(|f| matches!(f,
simple_agent_type::coercion::CoercionFlag::FixedTrailingComma)));Implementations§
Source§impl JsonishParser
impl JsonishParser
Sourcepub fn with_config(config: ParserConfig) -> Self
pub fn with_config(config: ParserConfig) -> Self
Create a parser with custom configuration.
Sourcepub fn parse(&self, input: &str) -> Result<ParserResult>
pub fn parse(&self, input: &str) -> Result<ParserResult>
Parse potentially malformed JSON.
Returns a ParserResult containing the parsed value, flags indicating
transformations applied, and a confidence score.
§Errors
Returns HealingError::ParseFailed if all parsing phases fail.
Returns HealingError::LowConfidence if confidence is below threshold.
§Example
use simple_agents_healing::parser::JsonishParser;
let parser = JsonishParser::new();
// Perfect JSON - no healing needed
let result = parser.parse(r#"{"key": "value"}"#).unwrap();
assert_eq!(result.confidence, 1.0);
assert!(result.flags.is_empty());
// Malformed JSON - healing applied
let result = parser.parse(r#"{"key": "value",}"#).unwrap();
assert!(result.confidence < 1.0);
assert!(!result.flags.is_empty());Trait Implementations§
Source§impl Debug for JsonishParser
impl Debug for JsonishParser
Auto Trait Implementations§
impl Freeze for JsonishParser
impl RefUnwindSafe for JsonishParser
impl Send for JsonishParser
impl Sync for JsonishParser
impl Unpin for JsonishParser
impl UnsafeUnpin for JsonishParser
impl UnwindSafe for JsonishParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more