I have a flat JSON data structure that I need to convert into a nested dictionary structure. For example:
Input:
{
'name': 'John',
'address.city': 'New York',
'address.zip': '10001',
'contacts[0].type': 'email',
'contacts[0].value': '[email protected]',
'contacts[1].type': 'phone',
'contacts[1].value': '123-456-7890',
'contacts[2].type': 'car'
'contacts[2].value': 'harley-davidson',
}
Expected Output:
{
"name": "John",
"address": {
"city": "New York",
"zip": "10001"
},
"contacts": [
{
"type": "email",
"value": "[email protected]"
},
{
"type": "phone",
"value": "123-456-7890"
}
{
"type": "car",
"value": "harley-davidson"
}
]
}
I need a general solution that can handle nested structures of arbitrary depth. Please help me write a Python function to achieve this functionality.