I am coding using Python, Flask, pandas. I am reading data from a REST API.
When I get the data from the REST API, the dispenserId
used to be an Integer meaning that each value started with a number different from 0
.
This weekend, I received dispenserId
s starting with a 0
(zero) character, so calling json.load(path_to_filenamen)
does not parse the JSON file anymore due to errors.
See the sample
{
"result": {
"dispensers": [
{
"dispenserId": 00000,
"dispenserName": "1st Floor",
"dispenserType": "H2",
"status": "Green",
"locationId": 12345
},
{
"dispenserId": 98765,
"dispenserName": "2nd Floor",
"dispenserType": "S4",
"status": "Green",
"locationId": 23456
},
{
"dispenserId": 00001,
"dispenserName": "3rd Floor",
"dispenserType": "H2",
"status": "Green",
"locationId": 34567
}
]
}
}
I receive Exception has occurred: TypeError string indices must be integers
when I call data["result"]["dispensers"]
.
How can I indicate to the JSON parser that the dispenserId
is a string instead of an Integer?