llm_json

Crates.iollm_json
lib.rsllm_json
version1.0.2
created_at2025-05-29 02:26:49.57543+00
updated_at2025-05-29 03:04:27.094793+00
descriptionRust crate to fix malformed JSON outputs from LLMs
homepage
repositoryhttps://github.com/oramasearch/llm_json
max_upload_size
id1693420
size50,537
Michele Riva (micheleriva)

documentation

README

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

Commit count: 20

cargo fmt