# llmjsonrepair: repairing truncated LLM JSON in Go

**URL:** <https://forum.golangbridge.org/t/llmjsonrepair-repairing-truncated-llm-json-in-go/42995>\
**Category:** Releases\
**Created:** [November 28, 2026, 1:36am UTC](https://forum.golangbridge.org/t/llmjsonrepair-repairing-truncated-llm-json-in-go/42995 "2026-11-28T01:36:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![qdxiao](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/qdxiao/32/18096_2.png) [@qdxiao](https://forum.golangbridge.org/u/qdxiao)\
**Post date:** [November 28, 2026, 1:36am UTC](https://forum.golangbridge.org/t/llmjsonrepair-repairing-truncated-llm-json-in-go/42995/1 "2026-11-28T01:36:56Z")

</div>

If an LLM response cuts off after `{"items":["a","b"`, Go’s `encoding/json` rejects it. `llmjsonrepair` can close the array and object, returning `{"items":["a","b"]}`. It has two entry points: `Repair` returns JSON text, and `Loads` returns parsed Go data.

One edge case worth calling out: if the response cuts off after `"total":`, the repaired output may contain `"total":null`. That makes the JSON parseable, but it doesn’t recover the missing value. I’d validate the result against the expected schema before using it downstream.

If you’ve handled truncated model output in Go, where do you draw the line between repairing and retrying? Small, anonymized examples are welcome.

> **[GitHub - qdxiao/llmjsonrepair: llmjsonrepair 是一个专门修复大语言模型（LLM）输出 JSON 格式错误的 Go...](https://github.com/qdxiao/llmjsonrepair)**
>
> llmjsonrepair 是一个专门修复大语言模型（LLM）输出 JSON 格式错误的 Go 语言库。当 ChatGPT、Claude 等 AI 模型生 成的 JSON 因输出截断、缺少引号、括号未闭合等问题无法正常解析时，该库能智能修复这些错误。支持深度嵌套结构修复 、多 JSON 对象流处理、上下文感知解析等功能。提供 Repair() 和 Loads() 两个简洁 API，一行代码即可修复残缺 JSON 并返回格式化结果或数据结构

Draft prepared with AI assistance; examples were run with Go 1.24.4.
