High-performance Go library for repairing invalid JSON documents, tuned for LLM-generated output
Go
126
97 commits
updated Aug 23, 2026
A Go library that repairs malformed JSON and JSON-adjacent text into valid JSON
None, True, and False into JSON literals.go get github.com/kaptinlin/jsonrepair
Requires Go 1.26.4+.
package main
import (
"fmt"
"log"
"github.com/kaptinlin/jsonrepair"
)
func main() {
repaired, err := jsonrepair.Repair("{name: 'John'}")
if err != nil {
log.Fatal(err)
}
fmt.Println(repaired)
}
Output:
{"name": "John"}
func Repair(text string) (string, error)
Repair returns the repaired JSON document or a structured *jsonrepair.Error when the input cannot be repaired.
repaired, err := jsonrepair.Repair(input)
if err != nil {
var repairErr *jsonrepair.Error
if errors.As(err, &repairErr) {
fmt.Printf("%s at position %d\n", repairErr.Message, repairErr.Position)
}
}
Sentinel errors support errors.Is:
ErrUnexpectedEndErrObjectKeyExpectedErrColonExpectedErrInvalidCharacterErrUnexpectedCharacterErrInvalidUnicodetask test # Run tests with race detection
task lint # Run golangci-lint and go mod tidy check
task # Run lint and test
Contributions are welcome. Open an issue to discuss substantial changes before submitting a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
This library is a Go port of Jos de Jong's JavaScript jsonrepair library.
94 followers · starred Apr 2026
260 followers · starred Jun 2025
High-performance Go library for repairing invalid JSON documents, tuned for LLM-generated output
Go
126
97 commits
updated Aug 23, 2026
A Go library that repairs malformed JSON and JSON-adjacent text into valid JSON
None, True, and False into JSON literals.go get github.com/kaptinlin/jsonrepair
Requires Go 1.26.4+.
package main
import (
"fmt"
"log"
"github.com/kaptinlin/jsonrepair"
)
func main() {
repaired, err := jsonrepair.Repair("{name: 'John'}")
if err != nil {
log.Fatal(err)
}
fmt.Println(repaired)
}
Output:
{"name": "John"}
func Repair(text string) (string, error)
Repair returns the repaired JSON document or a structured *jsonrepair.Error when the input cannot be repaired.
repaired, err := jsonrepair.Repair(input)
if err != nil {
var repairErr *jsonrepair.Error
if errors.As(err, &repairErr) {
fmt.Printf("%s at position %d\n", repairErr.Message, repairErr.Position)
}
}
Sentinel errors support errors.Is:
ErrUnexpectedEndErrObjectKeyExpectedErrColonExpectedErrInvalidCharacterErrUnexpectedCharacterErrInvalidUnicodetask test # Run tests with race detection
task lint # Run golangci-lint and go mod tidy check
task # Run lint and test
Contributions are welcome. Open an issue to discuss substantial changes before submitting a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
This library is a Go port of Jos de Jong's JavaScript jsonrepair library.
94 followers · starred Apr 2026
260 followers · starred Jun 2025