JSON Merge
Combine multiple JSON objects into a single unified object with controlled merge behavior.
What is JSON Merge?
JSON Merge is a utility node in Nocodo AI that combines two JSON objects into one. It gives you control over how deeply the merge operation works, allowing you to either merge only top-level properties or recursively combine nested structures throughout both objects.
How to use it?
-
Add JSON Merge to your workflow:
- Locate the JSON Merge node in the Conversion category of the node panel
- Drag and drop it onto your workflow canvas
-
Connect input sources:
- Connect two JSON objects to the required input anchors:
- First Object: Your primary JSON data
- Second Object: The JSON data you want to merge with the first
- Note: The second object's values will override the first object's values when there are conflicts
- Connect two JSON objects to the required input anchors:
-
Configure merge behavior:
- Select a merge depth option:
- Flat: Only merges top-level properties (second object overwrites first object's properties with the same name)
- Deep: Recursively merges nested objects (only overwrites conflicting values at each level)
- Select a merge depth option:
-
Choose output format:
- Set the output format based on your needs:
- JSON: For continued processing as a structured object
- Text: For string representation of the JSON
- Set the output format based on your needs:
-
Connect the output:
- Connect the output anchor to subsequent nodes that will use the merged data
Example of usage
Let's walk through a practical example of using JSON Merge to combine user profile data from multiple sources.
Creating a Complete User Profile
In this example, we'll merge basic user information with additional preference data to create a comprehensive user profile.
Workflow Setup
-
Create basic user information:
- Add a Text node with the following JSON content:
{
"userId": "user_12345",
"profile": {
"name": "Alex Smith",
"email": "alex@example.com"
},
"accountType": "standard"
}- Add a Data Conversion node connected to the Text node output
- Configure the Data Conversion to transform from Text to JSON
-
Create user preferences:
- Add another Text node with:
{
"profile": {
"location": "San Francisco",
"timezone": "PST"
},
"preferences": {
"theme": "dark",
"notifications": true
}
}- Add another Data Conversion node connected to this Text node
- Configure it to convert from Text to JSON
-
Merge the data:
- Add a JSON Merge node to your workflow
- Connect the first Data Conversion node's output to "First Object" input
- Connect the second Data Conversion node's output to "Second Object" input
- Set "Merge Depth" to "Deep"
- Set the output format to "JSON"
-
View the results:
- Connect the JSON Merge output to an Output node
When you run this workflow, the result will be a merged JSON object:
{
"userId": "user_12345",
"profile": {
"name": "Alex Smith",
"email": "alex@example.com",
"location": "San Francisco",
"timezone": "PST"
},
"accountType": "standard",
"preferences": {
"theme": "dark",
"notifications": true
}
}
Notice how the nested profile
object from both sources has been intelligently combined, preserving all properties.
Understanding merge behaviors
Flat merge
With flat merge, only top-level properties are combined. When both objects have the same property name at the top level, the second object's value completely replaces the first object's value.
Example:
First object:
{
"user": {
"name": "John",
"settings": {
"darkMode": true,
"fontSize": "medium"
}
},
"version": 1
}
Second object:
{
"user": {
"email": "john@example.com"
},
"lastUpdated": "2023-08-20"
}
Result with Flat merge:
{
"user": {
"email": "john@example.com"
},
"version": 1,
"lastUpdated": "2023-08-20"
}
Notice that the entire user
object was replaced, losing the name
property and all settings
.
Deep merge
With deep merge, the node recursively traverses all nested objects and intelligently combines properties at each level. Only conflicting values at the deepest level are overwritten.
Using the same input objects, a Deep merge would result in:
{
"user": {
"name": "John",
"email": "john@example.com",
"settings": {
"darkMode": true,
"fontSize": "medium"
}
},
"version": 1,
"lastUpdated": "2023-08-20"
}
The deep merge preserves all information by combining the nested objects rather than replacing them.
Tips for effective use
-
Choose the right merge type for your needs:
- Use Flat merge when you want to completely replace sections of data
- Use Deep merge when you want to preserve and enhance nested data structures
-
Consider the order of your objects:
- The second object's values take precedence when there are conflicts
- Place your base data as the first object and the "updates" as the second object
-
Handle arrays carefully:
- Arrays are replaced entirely rather than merged element-by-element
- If you need to combine arrays, consider using JSON Query first to manipulate them
-
When working with complex JSON:
- For debugging large structures, use the JSON Query node to check specific parts
- Consider breaking complex merges into multiple steps for more control
-
For dynamic workflows:
- Consider using the API Action node to fetch real-time data before merging
- Use Condition Routing after JSON Merge to handle different merge outcomes
By understanding how JSON Merge works and its different merge behaviors, you can effectively combine data from multiple sources in your Nocodo AI workflows.