Search code examples
dataweavemulesoftanypoint-studiomule4anypoint-platform

Update a Nested JSON object in MuleSoft DataWeave


Do I have a JSON object that looks like:

{"application":{"desiredState":"STOPPED"}}

I need to create this object at runtime in DataWeave based on the value of desiredState passed at runtime which could be STOPPED or STARTED.

How can I do that in DataWeave 2.0 ?


Solution

  • It seems that you want just to pass the value from the flow which I'll assume it is passed to the DataWeave script in a variable of the same name.

    %dw 2.0
    output application/json
    ---
    {"application": {"desiredState":vars.desiredState}}