export declare enum ScanError { None = 0, UnexpectedEndOfComment = 1, UnexpectedEndOfString = 2, UnexpectedEndOfNumber = 3, InvalidUnicode = 4, InvalidEscapeCharacter = 5, InvalidCharacter = 6 } export declare enum SyntaxKind { OpenBraceToken = 1, CloseBraceToken = 2, OpenBracketToken = 3, CloseBracketToken = 4, CommaToken = 5, ColonToken = 6, NullKeyword = 7, TrueKeyword = 8, FalseKeyword = 9, StringLiteral = 10, NumericLiteral = 11, LineCommentTrivia = 12, BlockCommentTrivia = 13, LineBreakTrivia = 14, Trivia = 15, Unknown = 16, EOF = 17 } /** * The scanner object, representing a JSON scanner at a position in the input string. */ export interface JSONScanner { /** * Sets the scan position to a new offset. A call to 'scan' is needed to get the first token. */ setPosition(pos: number): void; /** * Read the next token. Returns the token code. */ scan(): SyntaxKind; /** * Returns the current scan position, which is after the last read token. */ getPosition(): number; /** * Returns the last read token. */ getToken(): SyntaxKind; /** * Returns the last read token value. The value for strings is the decoded string content. For numbers its of type number, for boolean it's true or false. */ getTokenValue(): string; /** * The start offset of the last read token. */ getTokenOffset(): number; /** * The length of the last read token. */ getTokenLength(): number; /** * An error code of the last scan. */ getTokenError(): ScanError; } export interface ParseError { error: ParseErrorCode; offset: number; length: number; } export declare enum ParseErrorCode { InvalidSymbol = 1, InvalidNumberFormat = 2, PropertyNameExpected = 3, ValueExpected = 4, ColonExpected = 5, CommaExpected = 6, CloseBraceExpected = 7, CloseBracketExpected = 8, EndOfFileExpected = 9, InvalidCommentToken = 10, UnexpectedEndOfComment = 11, UnexpectedEndOfString = 12, UnexpectedEndOfNumber = 13, InvalidUnicode = 14, InvalidEscapeCharacter = 15, InvalidCharacter = 16 } export interface ParseOptions { disallowComments?: boolean; allowTrailingComma?: boolean; allowEmptyContent?: boolean; } export declare namespace ParseOptions { const DEFAULT: { allowTrailingComma: boolean; }; } export interface JSONVisitor { /** * Invoked when an open brace is encountered and an object is started. The offset and length represent the location of the open brace. */ onObjectBegin?: (offset: number, length: number) => void; /** * Invoked when a property is encountered. The offset and length represent the location of the property name. */ onObjectProperty?: (property: string, offset: number, length: number) => void; /** * Invoked when a closing brace is encountered and an object is completed. The offset and length represent the location of the closing brace. */ onObjectEnd?: (offset: number, length: number) => void; /** * Invoked when an open bracket is encountered. The offset and length represent the location of the open bracket. */ onArrayBegin?: (offset: number, length: number) => void; /** * Invoked when a closing bracket is encountered. The offset and length represent the location of the closing bracket. */ onArrayEnd?: (offset: number, length: number) => void; /** * Invoked when a literal value is encountered. The offset and length represent the location of the literal value. */ onLiteralValue?: (value: any, offset: number, length: number) => void; /** * Invoked when a comma or colon separator is encountered. The offset and length represent the location of the separator. */ onSeparator?: (character: string, offset: number, length: number) => void; /** * When comments are allowed, invoked when a line or block comment is encountered. The offset and length represent the location of the comment. */ onComment?: (offset: number, length: number) => void; /** * Invoked on an error. */ onError?: (error: ParseErrorCode, offset: number, length: number) => void; } /** * Creates a JSON scanner on the given text. * If ignoreTrivia is set, whitespaces or comments are ignored. */ export declare function createScanner(text: string, ignoreTrivia?: boolean): JSONScanner; /** * Parses the given text and invokes the visitor functions for each object, array and literal reached. */ export declare function visit(text: string, visitor: JSONVisitor, options?: ParseOptions): any;