utils_json: JSON Utilities

utils_jsonR Documentation

JSON Utilities

Description

Provides robust utilities for parsing potentially truncated or malformed JSON strings, commonly encountered in streaming LLM outputs.

A robust utility that uses a finite state machine to close open brackets, braces, and quotes to make a truncated JSON string valid for parsing.

Usage

fix_json(json_str)

Arguments

json_str

A potentially truncated JSON string.

Value

A repaired JSON string.

Examples

fix_json('{"name": "Gene...')
fix_json('[1, 2, {"a":')

aisdk documentation built on May 29, 2026, 9:07 a.m.