Feature request: Add JSON path parameter to JSONVisitor
functions
#50
Labels
feature-request
Request for new features or functionality
Milestone
Rationale
The
JSONVisitor
is quite useful for validating the content of a JSON document (and getting locations of incorrect data). However, currently it is rather cumbersome to find out at which JSON path in the document the parser is when a visitor function is called.Suggestion
It would therefore be good if some of the
JSONVisitor
functions had an extra parameter for theJSONPath
of the currently visited element:onObjectBegin
,onArrayBegin
,onLiteralValue
onObjectProperty
: Here theproperty
which is visited should probably not be part of the JSON pathFor the other functions adding a
JSONPath
would probably either not add much value (onObjectEnd
,onSeparator
,onArrayEnd
), or its behavior cannot be defined very well (onComment
,onError
).However, because
JSONPath
is a mutable array (and is therefore modified when the parser proceeds), it would be sanest to only hand out copies of it to the visitor functions. A performant way in which this could be implemented is to have a supplier function of JSON path so the copy is only created when the user actually uses the JSON path. For example:Based on the TypeScript documentation adding an extra function parameter should not be an issue.
What do yo think?
Workaround
Users implementing
JSONVisitor
can manually maintain a JSON path array, updating it in the respective visitor functions.Demo implementation (might contain bugs)
The text was updated successfully, but these errors were encountered: