I have created a JSON file from my Google search API results. I'm trying to read the file and parse the objects.
Each search result is one JSON array, which is shown below. I have 200 of these arrays in a single JSON file.
{
"kind": "customsearch#result",
"title": "text here",
"htmlTitle": "text here",
"link": "link here",
"displayLink": "text here",
"snippet": "text here",
"htmlSnippet": "text here",
"cacheId": "ID string",
"formattedUrl": "text here",
"htmlFormattedUrl": "link here",
"pagemap": {
"metatags": [
{
"viewport": "width=device-width, initial-scale=1"
}
],
"Breadcrumb": [
{
"title": "text here",
"url": "link here",
},
{
"title": "text here",
"url": "link here",
},
{
"title": "text here",
"url": "link here",
},
{
"title": "text here",
"url": "link here",
}
]
}
I'm having an issue reading the JSON file into json.load(s).
How do I read this file and start parsing the items?
def ingest_json(input):
try:
with open(input, 'r', encoding='UTF-8') as f:
json_data = json.loads(f)
except Exception:
print(traceback.format_exc())
sys.exit(1)
throws this error:
TypeError: the JSON object must be str,
bytes or bytearray, not 'TextIOWrapper'
def ingest_json(input):
try:
with open(input, 'r', encoding='UTF-8') as f:
json_data = json.load(f)
except Exception:
print(traceback.format_exc())
sys.exit(1)
throws this error:
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 269
column 2 (char 10330)