---
schema_version: "1"
id: 8c3a8a462da3de1a41d55c3dc33e98fe754eafa3e32b8b2854e7bd2456f1cf39
title: eval
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-runtime-functions-eval.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-runtime-functions-eval
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4ff298361e5d9f464f57885473367c33fd8c8c2aebf3b26191708adc1e93e13d
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# eval

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## eval(fileToExecute: String, fs: Dictionary<String>, readerInputs: Dictionary<ReaderInput> = {}, inputValues: Dictionary<Any> = {}, configuration: RuntimeExecutionConfiguration = {}): EvalResult

Evaluates a script with the specified context and returns the result of that evaluation.

_Experimental:_ This function is an experimental feature that is subject to change or removal from
future versions of DataWeave.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>fileToExecute</code></p></td><td><p>Name of the file to execute.</p></td></tr><tr><td><p><code>fs</code></p></td><td><p>An object that contains the file to evaluate.</p></td></tr><tr><td><p><code>readerInputs</code></p></td><td><p>Reader inputs to bind.</p></td></tr><tr><td><p><code>inputValues</code></p></td><td><p>Additional literal values to bind</p></td></tr><tr><td><p><code>configuration</code></p></td><td><p>The runtime configuration.</p></td></tr></tbody></table>

### Example

This example shows how `eval` behaves with different inputs.

#### Source

```DataWeave
%dw 2.0
import * from dw::Runtime

var jsonValue = {
   value: '{"name": "Mariano"}' as Binary {encoding: "UTF-8"},
   encoding: "UTF-8",
   properties: {},
   mimeType: "application/json"
}

var jsonValue2 = {
   value: '{"name": "Mariano", "lastName": "achaval"}' as Binary {encoding: "UTF-8"},
   encoding: "UTF-8",
   properties: {},
   mimeType: "application/json"
}

var invalidJsonValue = {
   value: '{"name": "Mariano' as Binary {encoding: "UTF-8"},
   encoding: "UTF-8",
   properties: {},
   mimeType: "application/json"
}

var Utils = "fun sum(a,b) = a +b"
output application/json
---
{
   "execute_ok" : run("main.dwl", {"main.dwl": "{a: 1}"}, {"payload": jsonValue }),
   "logs" : do {
     var execResult = run("main.dwl", {"main.dwl": "{a: log(1)}"}, {"payload": jsonValue })
     ---
     {
         m: execResult.logs.message,
         l: execResult.logs.level
     }
   },
   "grant" : eval("main.dwl", {"main.dwl": "{a: readUrl(`http://google.com`)}"}, {"payload": jsonValue }, {},{ securityManager: (grant, args) -> false }),
   "library" : eval("main.dwl", {"main.dwl": "Utils::sum(1,2)", "/Utils.dwl": Utils }, {"payload": jsonValue }),
   "timeout" : eval("main.dwl", {"main.dwl": "(1 to 1000000000000) map \$ + 1" }, {"payload": jsonValue }, {},{timeOut: 2}).success,
   "execFail" : eval("main.dwl", {"main.dwl": "dw::Runtime::fail('My Bad')" }, {"payload": jsonValue }),
   "parseFail" : eval("main.dwl", {"main.dwl": "(1 + " }, {"payload": jsonValue }),
   "writerFail" : eval("main.dwl", {"main.dwl": "output application/xml --- 2" }, {"payload": jsonValue }),
   "defaultOutput" : eval("main.dwl", {"main.dwl": "payload" }, {"payload": jsonValue2}, {},{outputMimeType: "application/csv", writerProperties: {"separator": "|"}}),
   "onExceptionFail": do  {
     dw::Runtime::try( () ->
         eval("main.dwl", {"main.dwl": "dw::Runtime::fail('Failing Test')" }, {"payload": jsonValue2}, {},{onException: "FAIL"})
     ).success
   },
   "customLogger":
        eval(
  "main.dwl",
           {"main.dwl": "log(1234)" },
   {"payload": jsonValue2},
    {},
   {
                  loggerService: {
                     initialize: () -> {token: "123"},
                     log: (level, msg, context) -> log("$(level) $(msg)", context)
                  }
                }
           )
}
```

#### Output

```Json
{
  "execute_ok": {
    "success": true,
    "value": "{\n  a: 1\n}",
    "mimeType": "application/dw",
    "encoding": "UTF-8",
    "logs": [

    ]
  },
  "logs": {
    "m": [
      "1"
    ],
    "l": [
      "INFO"
    ]
  },
  "grant": {
    "success": false,
    "message": "The given required permissions: `Resource` are not being granted for this execution.\nTrace:\n  at readUrl (Unknown)\n  at main::main (line: 1, column: 5)",
    "location": {
      "start": {
        "index": 0,
        "line": 0,
        "column": 0
      },
      "end": {
        "index": 0,
        "line": 0,
        "column": 0
      },
      "content": "Unknown location"
    },
    "stack": [
      "readUrl (anonymous:0:0)",
      "main (main:1:5)"
    ],
    "logs": [

    ]
  },
  "library": {
    "success": true,
    "value": 3,
    "logs": [

    ]
  },
  "timeout": true,
  "execFail": {
    "success": false,
    "message": "My Bad\nTrace:\n  at fail (Unknown)\n  at main::main (line: 1, column: 1)",
    "location": {
      "start": {
        "index": 0,
        "line": 0,
        "column": 0
      },
      "end": {
        "index": 0,
        "line": 0,
        "column": 0
      },
      "content": "Unknown location"
    },
    "stack": [
      "fail (anonymous:0:0)",
      "main (main:1:1)"
    ],
    "logs": [

    ]
  },
  "parseFail": {
    "success": false,
    "message": "Invalid input \"1 + \", expected parameter or parenEnd (line 1, column 2):\n\n\n1| (1 + \n    ^^^^\nLocation:\nmain (line: 1, column:2)",
    "location": {
      "start": {
        "index": 0,
        "line": 1,
        "column": 2
      },
      "end": {
        "index": 4,
        "line": 1,
        "column": 6
      },
      "content": "\n1| (1 + \n    ^^^^"
    },
    "logs": [

    ]
  },
  "writerFail": {
    "success": true,
    "value": 2,
    "logs": [

    ]
  },
  "defaultOutput": {
    "success": true,
    "value": {
      "name": "Mariano",
      "lastName": "achaval"
    },
    "logs": [

    ]
  },
  "onExceptionFail": false,
  "customLogger": {
    "success": true,
    "value": 1234,
    "logs": [

    ]
  }
}
```
