百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
J

json-repair

> AI 编程
开源

修复 JSON! 来自 LLM 的 JSON 变异解决方案。

381 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

修复 JSON! 来自 LLM 的 JSON 变异解决方案。

Contributors Forks Stargazers Issues GPL License

Repair JSON! Solution for JSON Anomalies from LLMs

Welcome to the json-repair, your go-to solution for fixing those pesky JSON anomalies that can sidetrack your Large Language Model (LLM) processes. Our toolkit is designed to be the Swiss Army knife for all your JSON repair needs.

Why Choose JSON Repair?

  • ️ GO Compatibility: Our library ensures a seamless experience for Go developers with its excellent compatibility.
  • Zero Dependencies: We've crafted a tool with zero external dependencies, keeping it lean and mean.
  • Rich Test Cases: Benefit from a comprehensive suite of test cases that ensure reliability and accuracy.
  • Auto-Detection & Repair: Intelligently identifies and corrects a wide range of JSON errors, from syntax to structural issues.
  • Terminal CLI Support: The feature can also be used in the command-line and can be chained with command pipes.
  • ⚙️ No Anxiety About Error: json-repair always gives the string result.
  • Open Source: Join a vibrant community of developers contributing to the ongoing evolution of the toolkit.

Supported Broken LLM JSON Output

  • Single quote "
  • Line feed \n
  • Improperly formatted JSON string {"key": TRUE, "key2": FALSE, "key3": Null
  • String with mixed quotes {'key': 'string', 'key2': false, \"key3\": null, \"key4\": unquoted}
  • Unclosed array [1, 2, 3, 4
  • Unclosed array object {"employees":["John", "Anna",
  • Standalone left bracket [
  • Standalone right bracket ]
  • Array with extra line breaks [[1\n\n]
  • Incorrect key-value pair {foo: [}
  • Correct JSON string {"text": "The quick brown fox won\'t jump"}
  • Incorrect key-value pair {"value_1": "value_2": "data"}
  • JSON string with comment {"value_1": true, COMMENT "value_2": "data"}
  • JSON string with leading spaces - { "test_key": ["test_value", "test_value2"] }
  • String containing a link { "content": "[LINK]("https://google.com")" }
  • Unclosed link string { "content": "[LINK](" }
  • Unclosed link and extra key string { "content": "[LINK](", "key": true }
  • Incorrect key-value pair {"key":"",}
  • etc.

(back to top)

Getting Started

To add the JSON Repair to your Go project, use the following command:

bash
go get github.com/RealAlexandreAI/json-repair

Usage

go
package main

import (
    "github.com/RealAlexandreAI/json-repair"
)

func main() {
    // broken JSON string from LLM
    in := "```json {'employees':['John', 'Anna', ```"

    jsonrepair.RepairJSON(in)

    // output:	{"employees":["John","Anna"]}
}

Additionally, there is MustRepairJSON for scenarios that are not suitable for error handling, such as pipes and trusted environments

For more examples, please refer to the Test Cases Or Online Playground

(back to top)

Library API

RepairJSON and MustRepairJSON keep their existing compact-string behavior. Headless callers that need the parsed value or advanced repair behavior can use the library options API:

go
input := `{"key": }`
result, err := jsonrepair.RepairWithOptions(input, jsonrepair.RepairOptions{
    Logging: true,
})

result.Value // parsed Go value
result.JSON  // compact repaired JSON
result.Log   // repair actions when Logging is true

The zero value of RepairOptions is the normal repair path. It also supports Strict, StreamStable, SkipJSONValidation, Logging, and schema-guided repair. RepairValue is the short form when only the parsed Go value is needed. RepairReader and RepairFile cover headless stream and file input.

Schema-guided repair accepts JSON Schema objects or boolean schemas. The standard and salvage modes support object, array, scalar, required, default, enum, const, items, additionalItems, patternProperties, additionalProperties, anyOf, oneOf, allOf, local $ref, common string and numeric constraints, and nested JSON-string containers. Salvage mode can drop invalid array items and recover schema-matching top-level fragments.

The Go implementation keeps Unicode output by default. Python-only Pydantic models and Python-specific json.dumps keyword arguments are not part of the Go API. The existing CLI flags and output behavior remain unchanged.

(back to top)

Terminal CLI

bash

brew install realalexandreai/tap-jsonrepair/jsonrepair

# from raw string
jsonrepair -i "{'employees':['John', 'Anna', "
# output: {"employees":["John", "Anna", "Peter"]}

# from file
jsonrepair -f .json

You can also download binary from Release, please refer to the Releases.

Roadmap

  • Convert project from Python
  • Minimum Go version
  • Cover test cases
  • Terminal CLI support
  • Workflow and GitHub Action
  • Add Homebrew tap
  • Support Full-width character detection
  • Smart/curly quote support
  • Multiple top-level JSON values
  • Duplicate key deduplication

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Related Project

  • python json_repair - Inspiration of json-repair.

License

Distributed under the GPLv3 License. See LICENSE for more information.

(back to top)

Contact

RealAlexandreAI - @RealAlexandreAI

Project Link: https://github.com/RealAlexandreAI/json-repair

(back to top)

Sponsor

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goagentcontextembeddingfunction-call

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类AI 编程
定价开源

> 相关工具

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.