I have a JSON file and would like to remove the beginning and end part
{
"records":
[{
"id":"53c5d162-3dd4-41ea-afd1-378b5be1bf04",
"userid":"u111124027",
"username":"Testuser",
"deviceid":"1185494411",
"devicename":"",
"start_date":"2020-05-19T06:46:55Z",
"fee":0.0,
"currency":"None",
"billing_state":"Bill",
"contact_id":"c410618636"
}],
"records_remaining":0
}
Parts to remove
{
"records": ,
"records_remaining":0
}
Code to remove the part
for element in data:
if 'records' in element:
del element['records']
Error:
del element['records']
TypeError: 'str' object does not support item deletion
If I remove the parts manually, I can manipulate the JSON via
if 'userid' in element:
del element['userid']
Is there a possibility to remove the two parts? I address a rest API and save the -get into a JSON-File. To continue working with the JSON-file, I have to remove these two parts
At the end the json-file should look like this:
[{
"id":"53c5d162-3dd4-41ea-afd1-378b5be1bf04",
"userid":"u111124027",
"username":"Testuser",
"deviceid":"1185494411",
"devicename":"",
"start_date":"2020-05-19T06:46:55Z",
"fee":0.0,
"currency":"None",
"billing_state":"Bill",
"contact_id":"c410618636"
}]