Nitin Mudgal
Nitin Mudgal

Reputation: 21

Dataweave scripting issue

I need to add "\" to my string in dataweave but it is not getting \ character

%dw 2.0 output application/json --- {  "pdEndDate":  "\/Date(" ++ vars.date.startDate ++ ")\/"   }

Actual:

{
  "pdEndDate": " /Date(1562895466000)N/"
}

Expected

{
  "pdEndDate": "\/Date(1562895466000)\/"
}

Upvotes: 0

Views: 114

Answers (1)

Shoki
Shoki

Reputation: 1538

You need to escape the \ with another \.

%dw 2.0 
output application/json 
--- 
{  "pdEndDate":  "\\/Date(" ++ vars.date.startDate ++ ")\\/"   }

But your output in JSON will be the following (with \\).

{
  "pdEndDate": "\\/Date(1562895466000)\\/"
}

Since in JSON \ is the escape char for strings, so you can't have just one, you need to escape it to include it in a string.

Upvotes: 4

Related Questions