1

In my Mule 4 flow I get a JSON Array similar to the following:

 [
     {
         "type": "error",
         "status": 404,
         "code": "not_found",
         "message": "Could not find the resource",
     },
     {
         "type": "error",
         "status": 401,
         "code": "",
         "message": "Could not find the specified ",
     }
 ]

I want to change the value of the message field to a vars.germanMessage variable for each JSON object.

I've tried to modify it with Dataweave 2 this way:

%dw 2.0
output application/java
 ---
(payload as Array) map {

    "message": vars.germanMessage

}

But this returns a new JSON message with only the message field.

The input type is Array<Object> and output type too.

Is there any way to replace the value without changing the rest of the message?

1 Answer 1

4

Yes just use mapObject

payload mapObject (value,key) -> {
    (key): if((key as String) == "message")) vars.germanMessage else value
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @machaval, but the source payload is an Array<Object> like the output payload so, What map type should I use instead of mapObject?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.