Learn R Programming

aisdk (version 1.1.0)

utils_json: 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)

Value

A repaired JSON string.

Arguments

json_str

A potentially truncated JSON string.

Examples

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

Run the code above in your browser using DataLab