jsonrepair

package
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package jsonrepair provides utilities to repair malformed JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Loads

func Loads(input string, opts ...Option) (any, error)

Loads takes a potentially malformed JSON string output from LLMs and attempts to repair it and parse it into a Go value.

func RepairJSON

func RepairJSON(input string, opts ...Option) (string, error)

RepairJSON takes a potentially malformed JSON string output from LLMs and attempts to repair it into a valid JSON string. It returns the repaired JSON string or an error if the input cannot be repaired.

Types

type LogEntry

type LogEntry struct {
	Context string `json:"context"`
	Text    string `json:"text"`
}

LogEntry represents a log entry with context and text.

func RepairJSONWithLog

func RepairJSONWithLog(input string, opts ...Option) (any, []LogEntry, error)

RepairJSONWithLog takes a potentially malformed JSON string output from LLMs and attempts to repair it into a valid JSON string, while also returning logs of the repair process.

type Option

type Option func(*options)

Option is a function that configures the JSON repairer.

func WithEnsureASCII

func WithEnsureASCII(value bool) Option

WithEnsureASCII sets whether to escape non-ASCII characters.

func WithSkipJSONLoads

func WithSkipJSONLoads() Option

WithSkipJSONLoads skips JSON parsing during load.

func WithStreamStable

func WithStreamStable() Option

WithStreamStable enables streaming-stable parsing.

func WithStrict

func WithStrict() Option

WithStrict enables strict parsing mode.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL