Skip to content

aotakeda/ai-json-fixer: An Efficient JSON Parser for Correcting Malformed Outputs from Large Language Models (LLMs) like GPT and Claude

admin

The LLMJSONParser is a specialized JSON parser crafted for handling poorly formatted JSON output from Large Language Models (LLMs) like GPT and Claude. Key features include:

  • Markdown Block Extraction: Extracts JSON from code blocks and inline code.
  • Trailing Content Removal: Eliminates explanatory text after valid JSON.
  • Quote Fixing: Corrects unescaped quotes within JSON strings.
  • Missing Comma Detection: Inserts missing commas between elements and properties.

It supports both single-line and multi-line JSON formats, addressing common issues like missing commas in compact LLM outputs. It requires no dependencies, is implemented in TypeScript/JavaScript, and includes comprehensive testing. The parser offers configurable parsing modes and includes error recovery for malformed input. Installation is straightforward via npm, and multiple usage examples demonstrate its capabilities, emphasizing its flexibility and robustness. The parser employs various options for customization, allowing tailored error handling and fix tracking.

Source link

Share This Article
Leave a Comment