Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

Merge 2 Json files

spuri5
7 - Meteor

I have 2 different JSON files which I want to merge as shown below: I also attached a screenshot of the JSON files.

Could you please help me with the solution

 

Thank you!

 

 

Input 1

{
"Name": "John",
"Birth": "Japan",
"Date": "25",
},
{
"Name": "Sam",
"Birth": "India",
"Date": "29",
}

 

Input 2:

 

"contactDetails":{
"Email": "john@yahoo.com",
"Phone": "123-999-1111",
"Home": "Kings"},
"contactDetails":{
"Email": "sam@yahoo.com",
"Phone": "123-999-2222",
"Home": "Queens"}   

 

Final Output:

 

"contactDetails":{
"Email": "john@yahoo.com",
"Phone": "123-999-1111",
"Home": "Kings"},
"contactDetails":{
"Email": "sam@yahoo.com",
"Phone": "123-999-2222",
"Home": "Queens"}

 

 

 

Input 1

Input_1.PNG

 

Input 2

Input_2.png

Final Output

Final Output.PNG

9 REPLIES 9
IraWatt
17 - Castor
17 - Castor

Hey @spuri5,

I've attached an example workflow using the JSON parse tool to extract the information and then JSON build to output the data as JSON. I had to add a few bits into your input text as it wasn't valid JSON so the output is slightly different.

IraWatt_0-1651512272053.png

Any questions please ask :)

Ira

 

apathetichell
18 - Pollux

your workflow makes an assumption that row 1 in input 1 corresponds to row 1 in input 2. Is this always true? If not - you need to figure out what your primary key is.

IraWatt
17 - Castor
17 - Castor

I agree @apathetichell, as JSON is unstructured there isn't a guarantee that there will be three attributes in each object. So a person ID of some sort would be required for a more robust solution. 

spuri5
7 - Meteor

Hello Ira,

 

Thank you for the response, but the output result is not quite the same. 

Also, we don't have any container for "people" in the final output.

 

Could you please help to generate the output as shown below.

 

spuri5_0-1651514460915.png

 

Thank you!

SP

IraWatt
17 - Castor
17 - Castor

No worries, the reason why I added people is because the input you gave is not valid JSON:

IraWatt_0-1651515183661.png

 

IraWatt
17 - Castor
17 - Castor

Once the JSON is corrected I'm happy to answer any issues you have with tweaking the workflow. You can check your JSON here JSON Online Validator and Formatter - JSON Lint.

spuri5
7 - Meteor

Thank you for the response, but the output result is not quite the same. 

Also, we don't have any container for "people" in the final output.

 

Also, we do have a primary key to the identity from both the files as shown below.

 

 

Input 1

{
"Primary Key": "1",
"Name": "John",
"Birth": "Japan",
"Date": "25",
},
{
"Primary Key": "2",
"Name": "Sam",
"Birth": "India",
"Date": "29",
}

 

Input 2

{
"Primary Key":"1",
"contactDetails":{
"Email":"john@yahoo.com",
"Phone":"123-999-1111",
"Home":"Kings"
}
},
{
"Primary Key":"2",
"contactDetails":{
"Email":"sam@yahoo.com",
"Phone":"123-999-2222",
"Home":"Queens"
}
}

 

Input 1

spuri5_0-1651515534777.png

 

Input 2

 

spuri5_1-1651515556829.png

 

 

spuri5
7 - Meteor

Hello Ira,

 

Please find updated json inputs.

 

Input 1

spuri5_0-1651515830251.png

 

Input 2

spuri5_1-1651515855470.png

 

 

IraWatt
17 - Castor
17 - Castor

Hey @spuri5,

Thanks for adding the primary Key as suggested by @apathetichell. I also added square brackets on both your inputs as it needed to be an array not 2 separate JSON objects for it to be valid JSON:

IraWatt_0-1651519569147.png

The output of the workflow is this:

 

{"Birth":"Japan",
"Date":"25",
"Name":"John",
"Primary Key":"1",
"contactDetails":{"Email":"john@yahoo.com","Home":"Kings","Phone":"123-999-1111"}},
{"Birth":"India",
"Date":"29",
"Name":"Sam",
"Primary Key":"2",
"contactDetails":{"Email":"sam@yahoo.com","Home":"Queens","Phone":"123-999-2222"}}

 

Very interesting problem, I've not used the JSON tools too much. If you have any queries on the workflow please ask. If the workflow solves the problem please give a green tick :) 

All the best,

Ira 

Labels