json24
Version:
FuzzyJSONParser is a robust JSON parser designed to handle and recover data from JSON strings with extraneous text and incomplete structures. It can parse JSON strings that include redundant pre/post content and recover from missing closing characters lik
43 lines (42 loc) • 1.58 kB
TypeScript
interface ParseOptions {
appendStrOnEnd?: string;
hasExplicitUndefined?: boolean;
}
/**
* A robust JSON parser designed to handle and recover data from JSON strings
* with extraneous text and incomplete structures. Ideal for parsing JSON strings that include
* redundant pre/post content or are missing closing characters like \", ], and }.
*/
export declare class FuzzyJsonParser {
private index;
private str;
private hasExplicitUndefined;
private appendStrOnEnd;
private currParseSettings;
constructor({ appendStrOnEnd, hasExplicitUndefined }?: ParseOptions);
/**
* Parses a JSON string while handling extraneous and incomplete structures.
* @param {string} jsonStr - The JSON string to parse.
* @param {string[]} requiredKeys - An optional array of keys that must be present in the JSON string.
* @param {ParseOptions} [options] - Optional settings to override the default parser options.
* @returns {any} The parsed JSON object or `null` if parsing fails.
*/
parse(jsonStr: string, requiredKeys?: string[], options?: ParseOptions): any;
private extractJsonLikeSegments;
private findAndParseValidJsonSegment;
private containsRequiredKeys;
private parseBase;
private resetParser;
private parseInternal;
private parseValue;
private parseObject;
private parseArray;
private parseString;
private parseNumber;
private parseBoolean;
private parseNull;
private parseUndefined;
private skipWhitespace;
private isDigit;
}
export { type ParseOptions };