How to access data in Feel expression with JSON key named "function"?

I have a JSON object like this

 {
  "body": {
    "message": {
      "role": "assistant",
      "content": "",
      "tool_calls": [
        {
          "function": {
            "name": "get_random_joke",
            "arguments": {
              "topic": "coffee"
            }
          }
        },
        {
          "function": {
            "name": "get_random_joke",
            "arguments": {
              "topic": "coffee"
            }
          }
        },
        {
          "function": {
            "name": "get_random_joke",
            "arguments": {
              "topic": "coffee"
            }
          }
        }
      ]
    }
  }
}

And I want to map it to a list like [“get_random_joke”, “get_random_joke”, “get_random_joke”].

I am unable to because the word function is protected?

Playground

You’re correct that function is a reserved keyword in FEEL! There are two ways to access JSON keys that are reserved keywords or contain special characters:

Solution 1: Using Backticks (Camunda Extension)

You can escape the reserved keyword using backticks:

for tool in body.message.tool_calls return tool.`function`.name

Solution 2: Using the get value() Function

You can use the built-in get value() function to access keys by string:

for tool in body.message.tool_calls return get value(tool, "function").name

Alternative: Simple List Projection

If you prefer a more concise approach, you can also use FEEL’s list projection syntax combined with backticks:

body.message.tool_calls.`function`.name

All of these expressions will give you the desired result: ["get_random_joke", "get_random_joke", "get_random_joke"]

References:

The backtick approach is probably the most readable for your use case!

Thanks! The backticks still fail in the playground but for tool in body.message.tool_calls return get value(tool, "function").name works.

Well done.

Perfect! I’m glad the get value() function approach worked for you.

You’re right that the backticks might not work in all FEEL environments - the get value(context, "key") function is the most reliable and universal way to access JSON keys that are reserved keywords or contain special characters.

Your final working solution:

for tool in body.message.tool_calls return get value(tool, "function").name

This successfully extracts the function names from your nested JSON structure and returns the list ["get_random_joke", "get_random_joke", "get_random_joke"] as desired.

Thanks for confirming the solution works! Feel free to reach out if you have any other FEEL expression questions.