Expression stored in database does not expand contained JS

Describe the problem/error/question

I am trying to store text that has an expression in it, inside a database for usage. Looks something like this:

Here is the JSON passed to us: {{ $json.body.requirements.toJsonString() }}

Now if I had this put directly in the expression field of a node, this would properly print out the entire JSON string.

Because this is stored in a database, I think its being passed to the expression as a full string, so instead of seeing requirements, I see the literal text {{ $json.body.requirements.toJsonString() }} get printed out.

How can I escape this in my database so that n8n properly renders the output?

  • n8n version: 1.61.0
  • Database (default: SQLite): SQLITE
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Unsure
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Official Image

Hi @blee

Could you share your workflow and demonstrate what you expect to see?

You can toggle a field between fixed and expression to have it evaluated or not, but I am not sure if this is what you’re asking… :eyes:

Thanks, sorry I meant to post it. here it is.

the notworking key is where I am trying to use the variable (or in my practical case database record)

@blee - That makes more sense, thanks! :slight_smile:

So basically, you want this expression to be extracted and evaluated at runtime in your workflow?

You can use this syntax for that:

$evaluateExpression(expression: string, itemIndex?: number)

So in your example it would be {{ $evaluateExpression($json.code) }}

1 Like

@ria - this is perfect! Thank you so much!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.