I have a dictionary which looks like below:
{
"permutations": [
{
"testname": "test1",
"file_type": "text",
"app_parent_folder": "folder",
"expected_result": "block"
},
{
"testname": "test2",
"file_type": "text",
"app_parent_folder": "folder",
"expected_result": "block"
}
]
}
I want to add a new object "rule_id": (no. of test cases) such that the json looks like below after the modification
{
"permutations": [
{
"testname": "test1",
"file_type": "text",
"app_parent_folder": "folder",
"expected_result": "block",
"rule_id": "1"
},
{
"testname": "test2",
"file_type": "text",
"app_parent_folder": "folder",
"expected_result": "block",
"rule_id": "2"
}
]
}
I tried using the below code but not getting the desired results
import json
from pprint import pprint
with open('example.json') as data_file:
data = json.load(data_file)
for rule_id_num in range(1,2):
data["permutations"].append('rule_id':rule_id_num)
pprint(data)
Please can someone help me regarding how can I add the dictionary in the above json file. Thank you in advance!!