Hey i have a json file eg: [ { "Reporter": "abc", "Created": "2015-05-28 11:29:16", "Assignee": "ABC", "Key": "JIRA-123" }, { "Reporter": "def", "Created": "2015-05-28 11:29:16", "Assignee": "DEF", "Key": "JIRA-234" } ]
in the above format, now i need to add some more entries in to this file from a dynamically generated data lets say the below data
{
"Reporter": "xyz",
"Created": "2015-05-28 11:29:16",
"Assignee": "XYZ",
"Key": "JIRA-456"
},
{
"Reporter": "utf",
"Created": "2015-05-28 11:29:16",
"Assignee": "UTF",
"Key": "JIRA-678"
}
but when i update this data into the above json file its again going to have a seperate list rather than combining.
like:
[
{
"Reporter": "abc",
"Created": "2015-05-28 11:29:16",
"Assignee": "ABC",
"Key": "JIRA-123"
},
{
"Reporter": "def",
"Created": "2015-05-28 11:29:16",
"Assignee": "DEF",
"Key": "JIRA-234"
}
]
[
{
"Reporter": "xyz",
"Created": "2015-05-28 11:29:16",
"Assignee": "XYZ",
"Key": "JIRA-456"
},
{
"Reporter": "utf",
"Created": "2015-05-28 11:29:16",
"Assignee": "UTF",
"Key": "JIRA-678"
}
]
but what i want is in the below format
[
{
"Reporter": "abc",
"Created": "2015-05-28 11:29:16",
"Assignee": "ABC",
"Key": "JIRA-123"
},
{
"Reporter": "def",
"Created": "2015-05-28 11:29:16",
"Assignee": "DEF",
"Key": "JIRA-234"
},
{
"Reporter": "xyz",
"Created": "2015-05-28 11:29:16",
"Assignee": "XYZ",
"Key": "JIRA-456"
},
{
"Reporter": "utf",
"Created": "2015-05-28 11:29:16",
"Assignee": "UTF",
"Key": "JIRA-678"
}
]
i tried with the modes r+, and a+ but i didn't get what i want.
with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'static', 'result', file_name + '_issues.json')), 'r+') as nInfo:
nInfo.write(json.dumps(file_data,indent=4, separators=(',', ': ')))
Can anyone please help in achieving this.
Txs! VK