'python - json , how to make a json flat
so i have a nested json that contains two groups , each group has a field that contains more sub groups i would like to pop all the sub groups out to flatten the json and remove the sub groups field
What is the correct way to do it
JSON :
[
{
"groupId": "a_group",
"version": "2.0.1",
"type": "jar",
"sub_group": [
{
"groupId": "a_1",
"version": "2.0.0",
"type": "jar",
"sub_group": []
},
{
"groupId": "a_2",
"version": "2.0.1",
"type": "jar",
"sub_group": [
{
"groupId": "a_1",
"version": "2.0.0",
"type": "jar",
"sub_group": []
},
],
}
],
},
{
"groupId": "c_group",
"version": "1.9.1",
"type": "jar",
"sub_group": [
{
"groupId": "a_1",
"version": "2.0.0",
"type": "jar",
"sub_group": []
},
],
},
}
This is the expected result: I need to pop all the sub groups and make them appear as a flat json like this
[{
"groupId": "a_group",
"version": "2.0.1",
"type": "jar",
"sub_group": []
},
{
"groupId": "a_1",
"version": "2.0.0",
"type": "txt",
"sub_group": []
},
{
"groupId": "a_2",
"version": "2.0.1",
"type": "jar",
"sub_group": []
},
{
"groupId": "c_group",
"version": "1.9.1",
"type": "jar",
"sub_group": []
},
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
