partialjson

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package partialjson parses the incomplete JSON emitted while tool-call arguments are streaming.

Index

Constants

View Source
const (
	AllowString Allow = 1 << iota
	AllowNumber
	AllowArray
	AllowObject
	AllowNull
	AllowBool
	AllowNaN
	AllowInfinity
	AllowNegativeInfinity

	AllowInf        = AllowInfinity | AllowNegativeInfinity
	AllowSpecial    = AllowNull | AllowBool | AllowInf | AllowNaN
	AllowAtom       = AllowString | AllowNumber | AllowSpecial
	AllowCollection = AllowArray | AllowObject
	AllowAll        = AllowAtom | AllowCollection
)

Variables

This section is empty.

Functions

func Parse

func Parse(input string, allowed ...Allow) (any, error)

Parse parses incomplete JSON. With no allow mask it permits every partial value, matching partial-json 0.1.7's default.

func ParseJSONWithRepair

func ParseJSONWithRepair(input string) (any, error)

ParseJSONWithRepair first parses strict JSON, then retries after RepairJSON.

func ParseStreamingJSON

func ParseStreamingJSON(input string) any

ParseStreamingJSON parses tool-call arguments as they arrive. It never returns an error; invalid, empty, and incomplete-null input becomes {}.

func RepairJSON

func RepairJSON(input string) string

RepairJSON escapes raw control characters and invalid backslash escapes inside JSON strings. It intentionally leaves structure untouched.

func StringifyStreamingJSON

func StringifyStreamingJSON(input string) ([]byte, error)

StringifyStreamingJSON parses an incomplete value and serializes the currently available result with JSON.parse/JSON.stringify property order.

Types

type Allow

type Allow uint16

Allow controls which incomplete JSON values Parse may return.

type MalformedJSONError

type MalformedJSONError struct {
	Message  string
	Position int
}

MalformedJSONError reports input that cannot be parsed as JSON, partial or complete.

func (*MalformedJSONError) Error

func (e *MalformedJSONError) Error() string

type PartialJSONError

type PartialJSONError struct {
	Message  string
	Position int
}

PartialJSONError reports an incomplete value disallowed by Parse's mask.

func (*PartialJSONError) Error

func (e *PartialJSONError) Error() string

Jump to

Keyboard shortcuts

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