Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Remove duplicate values in JSON file

spuri5
7 - Meteor

Hello, 

In my input file, I have Areacode, Areaname, StreetCode, and Zipcode, repeating multiple times and i just need it to show only once like in my expected outcome.

Also i want location to have nested values under location as shown below in the expected output.

 

 

Sample Input:

spuri5_0-1651777664330.png

 

Expected Output:

spuri5_0-1651777390648.png

 

15 REPLIES 15
Luke_C
17 - Castor
17 - Castor

Hi @spuri5 

 

Please include your data instead of screenshots. You'd first want to look at using a unique tool to get rid of the duplicates. Otherwise the JSON Build tool should do the trick.

spuri5
7 - Meteor

Please find the sample data below:

 

Record IDNameValue
1AreaCodeAB123
1AreaNameAB123_name
1StreetCodeTRC
1Location.Date2027-04-05
1Location.lpCodeAP0BUY
1Location.lpDescriptionAA
1Location.lpYear2090
1zipCodeFFAQ,FI19IA
1AreaCodeAB123
1AreaNameAB123_name
1StreetCodeTRC
1Location.Date2029-04-06
1Location.lpCodeAP0ABC
1Location.lpDescriptionZZ
1Location.lpYear2078
1zipCodeFFAQ,FI19IA
1AreaCodeAB123
1AreaNameAB123_name
1StreetCodeTRC
1Location.Date2033-04-06
1Location.lpCodeAP1LKJ
1Location.lpDescriptionQQ
1Location.lpYear2087
1zipCodeFFAQ,FI19IA
2AreaCodeCD123
2AreaNameCD123_name
2StreetCodeABT
2Location.Date4/6/2032
2Location.lpCodeAP1GTB
2Location.lpDescriptionBH
2Location.lpYear2094
2zipCodeFFAQ,FI19IA,SGHTWY
2AreaCodeCD123
2AreaNameCD123_name
2StreetCodeABT
2Location.Date4/6/2030
2Location.lpCodeAP1QWR
2Location.lpDescriptionOI
2Location.lpYear2077
2zipCodeFFAQ,FI19IA,SGHTWY

 

Luke_C
17 - Castor
17 - Castor

Hi @spuri5 

 

Here's how you can do this:

 

  1. Record ID to keep order
  2. Unique tool to remove dupes
  3. Sort to put back in order (based on record ID)
  4. JSON Build
  5. Summarize to create the list

 

Luke_C_0-1651781188753.png

 

 

spuri5
7 - Meteor

Hi Luke,

 

Below is the output I am getting with your workflow:

 

spuri5_0-1651785521199.png

 

[
{
"AreaCode":"AB123",
"AreaName":"AB123_name",
"StreetCode":"TRC",
"Location":{
"Date":"2027-04-05",
"lpCode":"AP0BUY",
"lpDescription":"AA",
"lpYear":"2090"
},
"zipCode":"FFAQ,FI19IA",
"Location":{
"Date":"2029-04-06",
"lpCode":"AP0ABC",
"lpDescription":"ZZ",
"lpYear":"2078",
"Date":"2033-04-06",
"lpCode":"AP1LKJ",
"lpDescription":"QQ",
"lpYear":"2087"
}
},
{
"AreaCode":"CD123",
"AreaName":"CD123_name",
"StreetCode":"ABT",
"Location":{
"Date":"4/6/2032",
"lpCode":"AP1GTB",
"lpDescription":"BH",
"lpYear":"2094"
},
"zipCode":"FFAQ,FI19IA,SGHTWY",
"Location":{
"Date":"4/6/2030",
"lpCode":"AP1QWR",
"lpDescription":"OI",
"lpYear":"2077"
}
}
]

 

But the expected out should be as shown below: Where the location should be appearing once!

spuri5_1-1651785583933.png

[
{
"AreaCode":"AB123",
"AreaName":"AB123_name",
"StreetCode":"TRC",
"zipCode":"FFAQ,FI19IA",
"Location":[
{
"Date":"2027-04-05",
"lpCode":"AP0BUY",
"lpDescription":"AA",
"lpYear":"2090"
},
{
"Date":"2029-04-06",
"lpCode":"AP0ABC",
"lpDescription":"ZZ",
"lpYear":"2078"
},
{
"Date":"2033-04-06",
"lpCode":"AP1LKJ",
"lpDescription":"QQ",
"lpYear":"2087"
}
]
},
{
"AreaCode":"CD123",
"AreaName":"CD123_name",
"StreetCode":"ABT",
"zipCode":"FFAQ,FI19IA,SGHTWY",
"Location":[
{
"Date":"2032-04-06",
"lpCode":"AP1GTB",
"lpDescription":"BH",
"lpYear":"2094"
},
{
"Date":"2030-04-06",
"lpCode":"AP1QWR",
"lpDescription":"OI",
"lpYear":"2077"
}
]
}
]

Luke_C
17 - Castor
17 - Castor

Hi @spuri5 

 

I see, let me look.

Luke_C
17 - Castor
17 - Castor

Hi @spuri5 

 

Give this a go. Had to handle the multiple locations per record. 

 

For future reference, the best way to figure out how to structure your data is to have your expected JSON as an input and see what the JSON Parse tool gives you. Then you just need to get alteryx to put the data in that format ahead of a JSON Build to get the same results

Luke_C_0-1651786542763.png

Luke_C_1-1651786559950.png

 

 

 

 

spuri5
7 - Meteor

Hi Luke,

 

Thank you so much for your help, it was my bad I forgot to add the values of the attributes (Location.Date and Location.lpCode)  within the "location" container that can be repeated for a larger set of data. Hence uniquing them out based on record id, name, and value is eliminating the duplicates which shouldn't be the case.

We want to retain all values as shown below.

 

spuri5_0-1651792140707.png

 

Input File: Please use this file as an Input

Record IDNameValue
1AreaCodeAB123
1AreaNameAB123_name
1StreetCodeTRC
1Location.Date2027-04-05
1Location.lpCodeAP0BUY
1Location.lpDescriptionAA
1Location.lpYear2090
1zipCodeFFAQ,FI19IA
1AreaCodeAB123
1AreaNameAB123_name
1StreetCodeTRC
1Location.Date2027-04-05
1Location.lpCodeAP0BUY
1Location.lpDescriptionZZ
1Location.lpYear2078
1zipCodeFFAQ,FI19IA
1AreaCodeAB123
1AreaNameAB123_name
1StreetCodeTRC
1Location.Date2033-04-06
1Location.lpCodeAP1LKJ
1Location.lpDescriptionQQ
1Location.lpYear2087
1zipCodeFFAQ,FI19IA
2AreaCodeCD123
2AreaNameCD123_name
2StreetCodeABT
2Location.Date4/6/2032
2Location.lpCodeAP1GTB
2Location.lpDescriptionBH
2Location.lpYear2094
2zipCodeFFAQ,FI19IA,SGHTWY
2AreaCodeCD123
2AreaNameCD123_name
2StreetCodeABT
2Location.Date2030-04-06
2Location.lpCodeAP1QWR
2Location.lpDescriptionOI
2Location.lpYear2094
2zipCodeFFAQ,FI19IA,SGHTWY

 

 

spuri5_1-1651792813302.png

 

Luke_C
17 - Castor
17 - Castor

Hi @spuri5 

 

Just a matter of only checking non-location fields for duplicates.

Luke_C_0-1651842430379.png

 

 

jakaur32
8 - Asteroid

thank you so much Luke, this workflow was really helpful for me as well.

Labels