Reputation: 128
I am dealing with Fox news API and the response is not recognized as a known datatype for me or Python. here is a sample of the response:
// API callback
__jp0({
"kind": "customsearch#search",
"url": {
},
"queries": {
"request": [
{
"totalResults": "791000",
"count": 10,
"startIndex": 1,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"siteSearch": "foxnews.com",
"siteSearchFilter": "i"
}
],
"nextPage": [
{
"totalResults": "791000",
"count": 10,
"startIndex": 11,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"siteSearchFilter": "i"
}
]})
Here is the API link to see the whole response Link I want to parse the response as json or any known datatype.
Upvotes: 2
Views: 371
Reputation: 1988
What you see there in the API is called the JSONP format.
It's a standard format and so you can just remove parentheses from the response and then load what's inside of parentheses like normal json:
data_json = response_json.split("(", 1)[1].strip(")")
parsed_json = json.loads(data_json)
Upvotes: 3