[JEP] proposal to add new 'error' function #163
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add 'error' function
Abstract
This JEP proposes a new function
error()
that raises a runtime error.This could be used to detect and raise an error when input JSON documents have unexpected data.
Motivation
AFAIK, there is no dedicated function to raise a runtime error within a JMESpath expression.
Specification
Add a new
error
function that takes a string expression.If the
error
function is evaluated, an error is raised with the specified string message.Rationale
Suppose we have the following JSON documents:
In this example, the values of
status
are eitherup
ordown
.Suppose the JMESpath author wants to:
status
to0
and1
.status
value is encountered. For example, when the value ofstatus
is set todegraded
.Since there is no built-in function to raise error, one may rely on the fact that some JMESpath expressions are invalid, e.g.,
to_number('bad')
would raise an error, but this is kludgy.Implementation Notes
Are there any details that implementers should try to follow?