How to convert multiple related rows in CSV into nested JSON using Nifi?
I have the following CSV:
| mobile | username | bill_id | bill_date | product_id | product_price |
| 9876543210 | John | AB10 | 2020-12-23 | X34 | 500 |
| 9876543210 | John | AB10 | 2020-12-23 | X35 | 230 |
| 9876543210 | John | AB22 | 2020-11-14 | X89 | 700 |
| 9999999999 | Alice | AC54 | 2019-12-20 | X10 | 109 |
And I want to convert them to the following structure:
{
"users": [
{
"mobile": "9876543210",
"username": "John",
"bills": [
{
"bill_id": "AB10",
"bill_date": "2020-12-23",
"products": [{
"product_id": "X34",
"product_price": "500",
},
{
"product_id": "X35",
"product_price": "230",
}]
},
{
"bill_id": "AB22",
"bill_date": "2020-11-14",
"products": [
{
"product_id": "X89",
"product_price": "700",
}]
}]
},
{
"mobile": "9999999999",
"username": "Alice",
"bills": [
{
"bill_id": "AC54",
"bill_date": "2019-12-20",
"products": [
{
"product_id": "X10",
"product_price": "109",
}]
}]
}]
}
I wasn't able to figure out how to group the related properties (e.g. product properties with the same bill_id) into an array. How should I go about doing this?

