Search code examples
anypoint-studiodataweavemulesoft

in mule 4 transformer Is it possible to use above defined key below


I am working on mule 4. I want to use the key defined above in transformer below. for example, my transformer is

%dw 2.0
output application/json
---
{
    name : usama,
    age : 24,
    value: age
}

here in the third key i.e. "data" I want to use the value of "age" key.

Can anyone help?

the output should be as defined below

{
    name : usama,
    age : 24,
    value: 24
}

Solution

  • Hi you can either define a global variable and reference it in both places or use a do block

    %dw 2.0
    output application/json
    var age = 24
    ---
    {
        name : "usama",
        age : age,
        value: age
    }