Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def extract_json_path_value(data, path):
"""Extract the value at JSON Path path from the data.
The input data is a Python datastructure, not a JSON string.
"""
path_expr = json_parser.parse(path)
matches = [match.value for match in path_expr.find(data)]
if matches:
if len(matches) > 1:
return matches
else:
return matches[0]
else:
raise ValueError(
"JSONPath '%s' failed to match on data: '%s'" % (path, data))