I have this json which has 3 parents and several child elements under each parent. I want to add one more common parent for all 3 current parents.
Currently I have:
{
"Parent1": {
"Key1": "Value",
"Key2": "Value",
"Key3": "Value"
},
"Parent2": {
"Key1": "Value",
"Key2": "Value",
"Key3": "Value"
},
"Parent3": {
"Key1": "Value",
"Key2": "Value",
"Key3": "Value"
}
}
What I want to have:
{
"Main parent": {
"Parent1": {
"Key1": "Value",
"Key2": "Value",
"Key3": "Value"
},
"Parent2": {
"Key1": "Value",
"Key2": "Value",
"Key3": "Value"
},
"Parent3": {
"Key1": "Value",
"Key2": "Value",
"Key3": "Value"
}
}
}
Below python3 code doesn't do the job:
with open ("myfile.json", 'r') as f:
myjson = json.load(f)
myjson["Main Parent"] = myjson
I would appreciate if you spread some light on this situation.
with open ("myfile.json", 'r') as f:
myjson = json.load(f)
myjson = {'Main Parent': myjson}
You could just create a new dict
and map Main Parent
to your child JSON:
new_json = dict()
new_json["Main Parent"] = myjson
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With