JSON Extractor
Features
Usage
from underdogcowboy import JSONExtractor
# Create a sample text with JSON embedded
sample_text = """
This is some random text. Here's our JSON data:
{"name": "John Doe", "age": 30, "city": "New York", "is_student": false}
And here's some more text after the JSON.
"""
# Define the expected keys
expected_keys = ["name", "age", "city", "is_student"]
# Create an instance of JSONExtractor
extractor = JSONExtractor(sample_text, expected_keys)
# Extract and parse the JSON
json_data, inspection_data = extractor.extract_and_parse_json()
# Print the results
print("Extracted JSON data:")
print(json_data)
print("\nInspection data:")
print(inspection_data)
# Define expected inspection data
expected_inspection_data = {
'number_of_keys': 4,
'keys': ["name", "age", "city", "is_student"],
'values_presence': {"name": True, "age": True, "city": True, "is_student": True},
'keys_match': True
}
# Check the inspection data against the expected data
is_correct, deviations = extractor.check_inspection_data(expected_inspection_data)
print("\nIs the extracted data correct?", is_correct)
if not is_correct:
print("Deviations found:")
print(deviations)
else:
print("No deviations found.")Use Cases
Limitations
Last updated