Merging nested JSON objects
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
If you have multiple nested JSON Objects (with no duplicate attribute names) like in this example object named Statement
:
{
"Amount": {
"Currency": "EUR",
"Value": "10.99"
},
"Valuation_Date": {
"Date": "2022-01-24"
},
"References": {
"FullRef": "CTC123456879",
"ClearRef": "123456789"
}
}
You can merge them into a flat one using the following code snipped:
{
{% for object in [Statement.Amount, Statement.Valuation_Date, Statement.References] %}
{% for key, value in object.items() %}
"{{ key }}": "{{ value }}",
{% endfor %}
{% endfor %}
}
To receive:
{
"Currency": "EUR",
"Value": "10.99"
"Date": "2022-01-24
"FullRef": "CTC123456879",
"ClearRef": "123456789"
}