Support for simple JSON extraction from the response body #106
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.
I have an API that returns a JSON array in the response body. I want to test that it is, in fact, an array. Unfortunately, that doesn't seem to be possible. It's possible to test an element of the array, but not the whole array.
My test looks like this:
This fails because the
jsonpath_mini
spec causes the validator to actually test(None, array)
. The reason is the logic in functionquery_dictionary()
:If a blank string is used as a query, then the expression
query.strip(delimiter).split(delimiter)
returns an array one element long, containing a blank string. So,dictionary=dictionary[x]
evaluates toNone
.The suggested fix tests for an empty string and, if it finds one, simply returns the
dictionary
which, in this case, will be the full array. Hence, both subscripting of the array, as well as the full array, can be supported.This is a general fix. A
jsonpath_mini
spec of an empty string simply causes the response body to be parsed as JSON and returned. So, you could test against anything.