1

We have a DataWeave expression wherein the payload, for some of the fields, special unicode control characters are coming.

This is leading to a WeaveExecutionException with the following message:

Exception while executing:
"userComment": "CA*2249*0*1763335*54133300896010155

^ Unexpected character '\u000a' at payload@[8:116] (line:column), expected '"'.

Below is the payload which we are getting. Here, in the field usercomment, a \u000a (new line character) is coming:

{
    "dcsId":"11840000000000001",
    "accessToken":"jaskjadkjsa",
    "profile": {
        "comments": {
            "feedback": [{
                "feedBackType":
                    "5",
                    "userComment": "CA*2249*0*1763335*54133300896010155
1" }
                        ]
                    }
                },
    "platform": "iphone"
}

Below is the logged Exception which we are getting in the console:

com.mulesoft.weave.mule.exception.WeaveExecutionException: Exception 
while executing:                                                                 
"userComment": "CA*2249*0*1763335*54133300896010155

^
Unexpected character '\u000a' at payload@[8:116] (line:column), expected 
'"'.

Below is the DataWeave script we are executing:

%dw 1.0
%output application/java
---
payload

Does DataWeave have no support for unicode control characters?

Attila
  • 2,823
  • 2
  • 27
  • 38
Mohit Mehrotra
  • 171
  • 1
  • 3
  • 12

3 Answers3

0

When you are doing transformations using either JSON to XML or XML to JSON please set Content-Type 'application/json; charset=UTF-8'.

Attila
  • 2,823
  • 2
  • 27
  • 38
Kamal Vamsi
  • 128
  • 4
0

There is a related question from earlier: How to get more information about dataweave exception in muleosft

According to this: you are supposed to escape the special, "control unicode characters".

Instead of new line, you are supposed to have \n in your JSON.

Please see also: How do I handle newlines in JSON?

For details see the JSON standard; the ECMA - 404.

In this document on the page 9, in the chapter "String" you can see a detailed description how the unicode control characters should be represented in JSON.

A JSON string must not contain a new-line charachter. Your JSON data has invalid format, what leads to an Exception.

Formal description of the JSON strings from the ECMA - 404

According to this: You have to make sure that the unicode control characters are properly escaped in your JSON strings.

Attila
  • 2,823
  • 2
  • 27
  • 38
0

In datawave use the operation as :string

In your case:

"userComment": "CA*2249*0*1763335*54133300896010155 as :string
Attila
  • 2,823
  • 2
  • 27
  • 38