Interface JSONVisitor
onArrayBegin?: ((offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: (() => JSONPath)) => boolean | void);
onArrayEnd?: ((offset: number, length: number, startLine: number, startCharacter: number) => void);
onComment?: ((offset: number, length: number, startLine: number, startCharacter: number) => void);
onError?: ((error: ParseErrorCode, offset: number, length: number, startLine: number, startCharacter: number) => void);
onLiteralValue?: ((value: any, offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: (() => JSONPath)) => void);
onObjectBegin?: ((offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: (() => JSONPath)) => boolean | void);
onObjectEnd?: ((offset: number, length: number, startLine: number, startCharacter: number) => void);
onObjectProperty?: ((property: string, offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: (() => JSONPath)) => void);
onSeparator?: ((character: string, offset: number, length: number, startLine: number, startCharacter: number) => void);
}
Properties
Optional
onArrayBegin
Invoked when an open bracket is encountered. The offset and length represent the location of the open bracket.
When false
is returned, the array items will not be visited.
Optional
onArrayEnd
Invoked when a closing bracket is encountered. The offset and length represent the location of the closing bracket.
Optional
onComment
When comments are allowed, invoked when a line or block comment is encountered. The offset and length represent the location of the comment.
Optional
onError
Invoked on an error.
Optional
onLiteralValue
Invoked when a literal value is encountered. The offset and length represent the location of the literal value.
Optional
onObjectBegin
Invoked when an open brace is encountered and an object is started. The offset and length represent the location of the open brace.
When false
is returned, the object properties will not be visited.
Optional
onObjectEnd
Invoked when a closing brace is encountered and an object is completed. The offset and length represent the location of the closing brace.
Optional
onObjectProperty
Invoked when a property is encountered. The offset and length represent the location of the property name.
The JSONPath
created by the pathSupplier
refers to the enclosing JSON object, it does not include the
property name yet.
Optional
onSeparator
Invoked when a comma or colon separator is encountered. The offset and length represent the location of the separator.
Visitor called by
visit
when parsing JSON.The visitor functions have the following common parameters:
offset
: Global offset within the JSON document, starting at 0startLine
: Line number, starting at 0startCharacter
: Start character (column) within the current line, starting at 0Additionally some functions have a
pathSupplier
parameter which can be used to obtain the currentJSONPath
within the document.