@solvers-hub/llm-json
Version:
A TypeScript SDK to extract and correct JSON from LLM outputs
57 lines (56 loc) • 1.84 kB
TypeScript
/**
* JsonCorrector class for correcting malformed JSON from LLM outputs.
*/
export declare class JsonCorrector {
/**
* Try to correct malformed JSON using various correction strategies.
* @param jsonString - The raw JSON string to correct.
* @returns The corrected JSON string if successful, or the original string if unsuccessful.
*/
static correctJson(jsonString: string): {
corrected: string;
wasCorrected: boolean;
};
/**
* Remove comments from JSON strings.
* @param jsonString - The JSON string that may contain comments.
* @returns The JSON string with comments removed.
*/
private static removeComments;
/**
* Fix unquoted property keys in JSON.
* @param jsonString - The JSON string to fix.
* @returns The corrected JSON string.
*/
private static fixUnquotedKeys;
/**
* Fix trailing commas in JSON.
* @param jsonString - The JSON string to fix.
* @returns The corrected JSON string.
*/
private static fixTrailingCommas;
/**
* Fix missing quotes around string values.
* @param jsonString - The JSON string to fix.
* @returns The corrected JSON string.
*/
private static fixMissingQuotes;
/**
* Fix missing closing braces and brackets.
* @param jsonString - The JSON string to fix.
* @returns The corrected JSON string.
*/
private static fixMissingBraces;
/**
* Fix single quotes used instead of double quotes.
* @param jsonString - The JSON string to fix.
* @returns The corrected JSON string.
*/
private static fixSingleQuotes;
/**
* Fix extra commas in JSON.
* @param jsonString - The JSON string to fix.
* @returns The corrected JSON string.
*/
private static fixExtraCommas;
}