#json-output #llm #json-fixer

bin+lib llm_json

Rust crate to fix malformed JSON outputs from LLMs

3 stable releases

Uses new Rust 2024

1.0.2 May 29, 2025

#1459 in Parser implementations

Download history 257/week @ 2025-10-07 470/week @ 2025-10-14 582/week @ 2025-10-21 445/week @ 2025-10-28 510/week @ 2025-11-04 442/week @ 2025-11-11 536/week @ 2025-11-18 418/week @ 2025-11-25 420/week @ 2025-12-02 457/week @ 2025-12-09 502/week @ 2025-12-16 519/week @ 2025-12-23 437/week @ 2025-12-30 627/week @ 2026-01-06 740/week @ 2026-01-13 848/week @ 2026-01-20

2,723 downloads per month
Used in 4 crates

MIT license

38KB
931 lines

LLM_JSON

A Rust library to repair broken JSON strings, particularly useful for handling malformed JSON output from Large Language Models.

This is a porting of the Python library json_repair, written by Stefano Baccianella and published under the MIT license.

All credits go to the original author for the amazing work.

Programmatic Usage

Install llm_json in your project:

cargo add llm_json

Then use it to repair your broken JSON strings:

use llm_json::{repair_json, loads, JsonRepairError};

fn main() {
  // Basic repair
  let broken_json = r#"{name: 'John', age: 30,}"#;
  let repaired = repair_json(broken_json, &Default::default())?;
  println!("{}", repaired); // {"name": "John", "age": 30}
  
  // Parse directly to Value
  let value = loads(broken_json, &Default::default())?;
}

CLI Usage

Install llm_json locally:

cargo install llm_json

Then use it to repair your broken JSON strings and files:

# Repair JSON from stdin
echo '{name: "John", age: 30,}' | llm_json

# Repair a file
llm_json broken.json

# Save to new file
llm_json input.json -o fixed.json

# Fix file in-place
llm_json broken.json --inline

License

MIT

Dependencies

~1.3–2.3MB
~44K SLoC