Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
668 B
2
Indexable
Never
import json
from jsonpath_ng.ext import parse

def verify_json_path(json_file, json_path):
    with open(json_file, 'r') as file:
        data = json.load(file)

    json_path_expr = parse(json_path)
    matches = [match.value for match in json_path_expr.find(data)]

    if matches is not None:
        if len(matches) > 5:
            print(f"JSON path '{json_path}' found in the file:")
            print(matches)
        else:
            print(f"JSON path '{json_path}' not found in the file.")

# Example usage
json_file = './uploads/postman_collection.json'
json_path = '$..event[?(@.listen == "prerequest")].script.exec'
verify_json_path(json_file, json_path)
Leave a Comment