Nikhil Udayakumar
Nikhil Udayakumar

Reputation: 21

Facing issue while data transformation in mule 3

I am trying to convert the output of a database into json using transform message component.

This is the input payload

[{
    "usd ": 0.0, 
    "goal": 3041920,
    "Inr": 0.0,
}]

Data weave exp inside transformer

%dw 1.0
%output application/json
---
payload map ((payload01 , indexOfPayload01) -> {
    "usd ": payload01.usd ,
    "goal": payload01.goal,
    "Inr": payload01.Inr,

}

I have done the mapping in transform message and whenever testing the flow i am getting exception

com.mulesoft.weave.mule.exception.WeaveExecutionException

Can someone Help

Thanks, Nikhil

Upvotes: 0

Views: 211

Answers (2)

user6878821
user6878821

Reputation:

You also don't quote the keys in dataweave template. See the samples here https://docs.mulesoft.com/mule-runtime/3.9/dataweave-language-introduction

%dw 1.0
%output application/json
---
payload map ((payload01 , indexOfPayload01) -> 
  { 
    usd: payload01.'usd ', 
    goal: payload01.goal, 
    Inr: payload01.Inr
  })

Upvotes: 0

aled
aled

Reputation: 25664

The input JSON and the script have a few errors. First, the last comma in each attribute has to be removed. To access the "usd " key you need to use quotes in the key name. Having a quote in a key is weird anyway.

Corrected script:

%dw 1.0
%output application/json
---
payload map ((payload01 , indexOfPayload01) -> 
  { 
    "usd": payload01.'usd ', 
    "goal": payload01.goal, 
    "Inr": payload01.Inr
  })

Corrected input:

[{ "usd ": 0.0, "goal": 3041920, "Inr": 0.0 }]

Output:

[
  {
    "usd": 0.0,
    "goal": 3041920,
    "Inr": 0.0
  }
]

Upvotes: 1

Related Questions