Forum Discussion
@Rudradip This is a follow up after a considerable period of time but I wanted to answer the question.
Assuming in input document to the JSON Generator like:
{
"Body": "456",
}
This concatenation in the JSON Generator WILL NOT work:
[
{
"Response": {
"Message": "Thank you for your message, which was $Body"
}
}
]
and will result in an error like
Failed to validate the output
Resolution:
Verify that the table values and the template are correct
Reason:
Unexpected character ('4' (code 52)): was expecting comma to separate Object entries
But if you use a Velocity Directive, the following WILL work:
#set( $message = "Thank you for your message, which was $Body" )
[
{
"Response": {
"Message": $message
}
}
]
The output document will look like:
[{
"Response": {
"Message": "Thank you for your message, which was \"456\""
}
}]
Do note that the $Body
value has been wrapped in quotes. I’ll investigate if there is a way to remove those.
Thanks. This is very helpful
- Ajay_Chawda7 years agoContributor
Hi Pavan,
test123_2019_06_20.slp (5.1 KB)- pavan_gangisett7 years agoNew Contributor II
Hi Ajay,
it is not working as expected.
Input Json:
[
{department_Id: 1,
details: [
{ firstname: “a”, lastname: “b”, id: 1},
{ firstname: “c”, lastname: “d”, id: 2}
]
},
{department_Id: 2,
details: [
{ firstname: “e”, lastname: “f”, id: 3},
{ firstname: “g”, lastname: “h”, id: 4}
]
}
]Expected Output Json:
[
{department_Id: 1,
users: [
{ name: “a b”, id: 1},
{ name: “c d”, id: 2}
]
},
{department_Id: 2,
users: [
{ name: “e f”, id: 3},
{ name: “g h”, id: 4}
]
}
]Think this does what you’re looking for.
I used the first mapper to re-map the entries in the details array and then the second mapper to rename the details property to users.
Here is what I was mentioning about using the Mapping Root. This is very helpful for working with nested arrays.
Here is the complete example for you to try out. Good luck with your work.
make-users_2019_06_20.slp (5.5 KB)
Related Content
- 10 months ago
- 4 months ago
- 4 months ago