Updated: Sep 4
The video version of this article can be found at the end of the post.
In this post, I will explain what object concatenation is and how to utilize it.
You may be familiar with other language’s concatenation functions, especially when using two strings. For example:
“Hello”.concat(“ World!”); “Hello” + “ World!”; print(“Hello”, “ World!”) Concatenate ‘string “Hello” “ World!”
This can also be achieved in DataWeave with the ++ function.
“Hello” ++ “ World”
But, can this also be used for objects? Keep reading to find out!
What is object concatenation?
When I say “object concatenation”, I mean the action of combining 2 different objects, and creating one single object containing all the fields (or keys) and values of these objects.
For example, we have these 2 JSON objects:
And we want to achieve this:
In the end, we have a single object, that contains everything that the other 2 objects had. This is object concatenation.
Object concatenation using ++
The most commonly used way to achieve object concatenation in DataWeave, is the ++ function.
The previous operation, using DW, would look something like this: