Expand description
§LLM JSON Repair
A Rust library to repair broken JSON strings, particularly useful for handling malformed JSON output from Large Language Models (LLMs).
This is a porting of the Python library json_repair (https://github.com/mangiucugna/json_repair), written by Stefano Baccianella (https://github.com/mangiucugna) and published under the MIT license. All credits go to the original author for the amazing work.
§Features
- Fix missing quotes around keys and values
- Handle misplaced commas and missing brackets
- Repair incomplete arrays and objects
- Remove extra non-JSON characters
- Auto-complete missing values with sensible defaults
- Preserve Unicode characters
§Usage
use llm_json::{repair_json, loads, JsonRepairError};
// Basic repair
let broken_json = r#"{name: 'John', age: 30,}"#;
let repaired = repair_json(broken_json, &Default::default()).unwrap();
println!("{}", repaired); // {"name": "John", "age": 30}
// Parse directly to Value
let value = loads(broken_json, &Default::default()).unwrap();
Structs§
- Repair
Options - Configuration options for JSON repair
Enums§
- Json
Repair Error - Errors that can occur during JSON repair
Functions§
- from_
file - Repair and parse JSON from a file
- load
- Repair and parse JSON from a reader
- loads
- Repair and parse a JSON string, returning the parsed Value
- repair_
json - Repair a broken JSON string