I'm working on a project IN PYTHON where I need to read and write from and to a JSON file.
The JSON file's contents look like this:
{
"buildings": [
{
"name": "Trump Towers",
"nr": "1",
"worth": "399"
},
{
"name": "Penning Towers",
"nr": "2",
"worth": "299"
}
],
"staff": [
{
"name": "D Trump",
"nr": "1",
"worth": "399"
},
{
"name": "Mr Henry",
"nr": "2",
"worth": "299"
}
]
}
Again, I need to be able to read, add and delete the individual buildings' and staff members' data
(THE FOLLOWING IS NOT IN CORRECT SYNTAX, BUT THAT'S WHY I'M ASKING, I NEED HELP WITH THIS)
(syntax not accurate) eg.
>>> read name of building nr 1
Trump Towers
>>> delete 'Trump Towers' from buildings (output to the file)
{
"buildings": [
{
"name": "Penning Towers",
"nr": "2",
"worth": "299"
}
],
"staff": [
{
"name": "D Trump",
"nr": "1",
"worth": "399"
},
{
"name": "Mr Henry",
"nr": "2",
"worth": "299"
}
]
}
>>> set 'Penning Towers' from buildings nr to 1
{
"buildings": [
{
"name": "Penning Towers",
"nr": "1",
"worth": "299"
}
],
"staff": [
{
"name": "D Trump",
"nr": "1",
"worth": "399"
},
{
"name": "Mr Henry",
"nr": "2",
"worth": "299"
}
]
}
>>> add 'Jake' with nr '3' and worth '999' to staff
{
"buildings": [
{
"name": "Penning Towers",
"nr": "1",
"worth": "299"
}
],
"staff": [
{
"name": "D Trump",
"nr": "1",
"worth": "399"
},
{
"name": "Jake",
"nr": "2",
"worth": "299"
},
{
"name": "Mr Henry",
"nr": "3",
"worth": "999"
}
]
}