adam_gataev
2 years agoNew Contributor II
Creating complex nested JSON from CSV file
I am reading a CSV/XLSX file (could be an sql table as well) with the follwing structure (file attached below as well):
Branch | Year | Type | ParentNumber | CurrentNumber | Structure | Level | Language1 | Language1_Value | Language2 | Language2_Value | CreationDate | LastUpdate |
1234 | 2024 | AAA | NULL | 12342024010000 | 01 | 1 | NL | voornaam | EN | first name | 05/06/2024 | 05/06/2024 |
1234 | 2024 | AAA | 12342024010000 | 12342024010100 | 01.01 | 2 | NL | achternaam | EN | last name | 05/06/2024 | 05/06/2024 |
1234 | 2024 | AAA | NULL | 12342024020000 | 02 | 1 | NL | geboortedatum | EN | birthday | 05/06/2024 | 05/06/2024 |
1234 | 2024 | AAA | NULL | 12342024030000 | 03 | 1 | NL | geslacht | EN | gender | 05/06/2024 | 05/06/2024 |
1234 | 2024 | AAA | 12342024030000 | 12342024030100 | 03.01 | 2 | NL | opslaan | EN | save | 05/06/2024 | 05/06/2024 |
1234 | 2024 | AAA | 12342024030100 | 12342024030101 | 03.01.01 | 3 | NL | versturen | EN | send | 05/06/2024 | 05/06/2024 |
1234 | 2024 | AAA | 12342024030100 | 12342024030102 | 03.01.02 | 3 | NL | sluiten | EN | close | 05/06/2024 | 05/06/2024 |
I want to transform this table (could be thousands of rows) to the following JSON structure(file attached below as well):
{
"Branch": 1234,
"Year": 2024,
"Type": "AAA",
"MaxLevel": 3,
"Level1": [
{
"ParentNumber": "NULL",
"CurrentNumber": 12342024010000,
"Structure": "01",
"Level": 1,
"Translations": [
{
"Language1": "NL",
"Language1_Value": "voornaam"
},
{
"Language2": "EN",
"Language2_Value": "first name"
}
],
"LastUpdate": "2024-05-06",
"Level2": [
{
"ParentNumber": 12342024010000,
"CurrentNumber": 12342024010100,
"Structure": "01.01",
"Level": 2,
"Translations": [
{
"Language1": "NL",
"Language1_Value": "achternaam"
},
{
"Language2": "EN",
"Language2_Value": "last name"
}
],
"LastUpdate": "2024-05-06"
}
]
},
{
"ParentNumber": "NULL",
"CurrentNumber": 12342024020000,
"Structure": "02",
"Level": 1,
"Translations": [
{
"Language1": "NL",
"Language1_Value": "geboortedatum"
},
{
"Language2": "EN",
"Language2_Value": "birthday"
}
],
"LastUpdate": "2024-05-06"
},
{
"ParentNumber": "NULL",
"CurrentNumber": 12342024030000,
"Structure": "03",
"Level": 1,
"Translations": [
{
"Language1": "NL",
"Language1_Value": "geslacht"
},
{
"Language2": "EN",
"Language2_Value": "gender"
}
],
"LastUpdate": "2024-05-06",
"Level2": [
{
"ParentNumber": 12342024030000,
"CurrentNumber": 12342024030100,
"Structure": "03.01",
"Level": 2,
"Translations": [
{
"Language1": "NL",
"Language1_Value": "opslaan"
},
{
"Language2": "EN",
"Language2_Value": "save"
}
],
"LastUpdate": "2024-05-06",
"Level3": [
{
"ParentNumber": 12342024030100,
"CurrentNumber": 12342024030101,
"Structure": "03.01.01",
"Level": 3,
"Translations": [
{
"Language1": "NL",
"Language1_Value": "versturen"
},
{
"Language2": "EN",
"Language2_Value": "send"
}
],
"LastUpdate": "2024-05-06"
},
{
"ParentNumber": 12342024030100,
"CurrentNumber": 12342024030102,
"Structure": "03.01.02",
"Level": 3,
"Translations": [
{
"Language1": "NL",
"Language1_Value": "sluiten"
},
{
"Language2": "EN",
"Language2_Value": "close"
}
],
"LastUpdate": "2024-05-06"
}
]
}
]
}
],
"CreationDate": "2024-05-06",
"LastUpdate": "2024-05-06"
}
Is this even possible in the first place?
Can someone help me out?
Thank you!
Hello @negi_sagar,
You can try by using a Mapper Snap with Pass-through enabled:
For Choices try using the below expression:
$Choices.extend({[Math.max(...$Choices.keys().map(x => parseInt(x))).toString()]:$Choices.get(Math.max(...$Choices.keys().map(x => parseInt(x))).toString()).extend({"TextEntry":"true"})})
Sample pipeline:
SL-comm-add-field-to-max-in-json_2023_03_20.slp (4.4 KB)Let me know if this helps you.
BR,
Aleksandar.Thank you Aleksandar for answering this quickly and it worked.
Can you tell me some resources from where I learn to create these expressions?