Merge 2 Json files
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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 2
Final Output
Solved! Go to Solution.
- Labels:
- API
- Custom Tools
- Interface Tools
- Join
- Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
Any questions please ask :)
Ira
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
Thank you!
SP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
No worries, the reason why I added people is because the input you gave is not valid JSON:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
Input 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hello Ira,
Please find updated json inputs.
Input 1
Input 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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:
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
