Search code examples
dataweavemulesoft

Dataweave : Is it possible to execute a string as code?


Assuming there is a property in a file.properties like : aaa.code=now() - |P2D|

%dw 2.0
output application/json
---
{ "from": p('aaa.code') }

The property arrives as a string and is not interpreted. How / is it possible to interpret the code in Dataweave 2 ? I found eval or execute but both are experimental and it does not fit.


Solution

  • Use read function to get the desired result:

    https://docs.mulesoft.com/dataweave/2.4/dw-core-functions-read

    %dw 2.0
    output application/json
    ---
    read(p('aaa.code'))