Closed manueligno78 closed 8 years ago
This will not work since the your json object
is an array not proper dictionary response. The function below is used to compute jsonpath_mini
@staticmethod
def query_dictionary(query, dictionary, delimiter='.'):
""" Do an xpath-like query with dictionary, using a template if relevant """
# Based on
# http://stackoverflow.com/questions/7320319/xpath-like-query-for-nested-python-dictionaries
try:
stripped_query = query.strip(delimiter)
if stripped_query:
for x in stripped_query.split(delimiter):
try:
x = int(x)
dictionary = dictionary[x]
except ValueError:
dictionary = dictionary[x]
except:
return None
return dictionary
So no way to get it works.. neither with next releases?
@manueligno78 and @rsukla-handy Actually... we added a feature that allows this with the last release: the JMESpath extractor --https://github.com/svanoort/pyresttest/blob/master/advanced_guide.md#extractor-jmespath
You'll need to have the JMESPath library installed for it to work: PyRestTest does not auto-install it, because it's attempting to keep core dependencies minimal, but the jmespath extractor will automatically become available when the necessary libraries are installed.
Thank you, my mistake.
I'm trying to validate some responses and i'm using jsonpath_mini extractor. This is the response, it is a json array, i have to extract the value of the id of the first array element:
This is my validator:
This validation at the moment fails, but shouldn't as indeed testing it against http://jmespath.org/
The extractor seems to return "None" instead of "Vendor" as reported by test output: