How do I insert an object in nested lists. I get json response that doesn't return a a certain object for certain a condition
data.json
Note: in 'steps' list, the 3rd index did not return result
[
{
"elements": [
{
"keyword": "Scenario",
"name": "valid user can login site",
"steps": [
{
"name": "a valid user name and password",
"result": {
"status": "passed"
}
},
{
"name": "a valid user clicking on the login button after typing in user name and password",
"result": {
"status": "passed"
}
},
{
"name": "map should display"
}
]
}
],
"keyword": "Feature",
"name": "login",
"status": "passed"
}
]
What I want to achieve:
I want to insert a 'result' object if it is absent
[
{
"elements": [
{
"keyword": "Scenario",
"name": "valid user can login site",
"steps": [
{
"name": "a valid user name and password",
"result": {
"status": "passed"
}
},
{
"name": "a valid user clicking on the login button after typing in user name and password",
"result": {
"status": "passed"
}
},
{
"name": "map should display"
"result": {
"status": "skipped"
}
}
]
}
],
"keyword": "Feature",
"name": "login",
"status": "passed"
}
]
What i've done so far (pseudo):
with open('data.json') as data_file:
data = json.load(data_file)
#nested for loops??
#if x.has_key('result') == False
#insert result object