Search code examples
muledataweavemule-esbmulesoftmule4

How to get a value from an array in Mule 4


I wanted to get a value in an array without using absolute array positioning. Here is my json payload.

{ 
  "xyz":{ 
    "abc":[ 
      { 
        "account":[ 
          { 
            "value":"savings"
          }
        ]
      }
    ]
  }
}

How to get the value savings using Data Weave..


Solution

  • You can also do that. I supposed you don't want to use at all indexes and that there is only one key value in the payload:

    %dw 2.0
    output application/json
    
    var data = {"xyz": {"abc":["account":[{"value":"savings"}]]}}
    ---
    data..value reduce $