@toolsycc/json-repair
Version:
A robust utility to repair JSON strings - fix malformed or broken JSON, especially from LLM output like ChatGPT.
18 lines (17 loc) • 647 B
TypeScript
export interface RepairOptions {
safeMode?: boolean;
extractJson?: boolean;
encodeAscii?: boolean;
returnObject?: boolean;
logging?: boolean;
}
/**
* Attempts to extract a valid JSON block (between braces or brackets) from a string
*/
export declare function extractJsonFromText(input: string): string;
/**
* Repairs a potentially incorrect JSON string by applying various
* transformations (extraction, removal of trailing commas, quoting, etc.).
* Returns either a JSON string (default) or a JS object (if `returnObject` is true).
*/
export declare function repairJson(input: string, options?: RepairOptions): unknown;