1

This is my code.

%dw 2.0
output application/java
var plantDesc = payload.somevalue
var str1 = "\"plantDescFull\" = " ++ "\"" ++ plantDesc ++ "\""
---
{
   testValue : str1
}

I need the output to be

{
   testValue : ""plantDescFull" = "someValue""
}

I have tried ways to set str1 but doesn't seem to work. Either I am not able to escape the the quotes or unable to put the value of plantDesc variable into str1

All help is appreciated

Nadeem
  • 77
  • 1
  • 12

3 Answers3

2

I think it works if you define it with single quotes:

var str1 = '"plantDescFull" = "' ++ plantDesc ++ '"'
afelisatti
  • 2,770
  • 1
  • 13
  • 21
0

I was able to resolve the problem.

Actual problem was something else. I had to rework my code.

Basically payload.somevalue is an object. So what I was doing was completely wrong. We cannot concatenate a string and an object.

Nadeem
  • 77
  • 1
  • 12
0

You can't have double quotes inside a string without having them escaped. String interpolation is always a good and clean approach

%dw 2.0
output application/java
var plantDesc = payload.somevalue default ''
---
{
   testValue : "'plantDescFull' = '$(plantDesc)'"
}

If you must have double quotes you would escape them similarly with:

%dw 2.0
output application/json
var plantDesc = payload.somevalue default ''
---
{
   testValue : "\"plantDescFull\" = \"$(plantDesc)\""
}
maddestroyer7
  • 233
  • 1
  • 5