Escaping expressions to avoid unneeded interpolation

Describe the problem/error/question

Is it possible to escape an interpolation expression (i.e. {{ $json.data.item }} ) so that it is passed as literal string?
The problem is that i need to update 1 workflow (child) from another (parent) using the Update Workflow node. Some stuff in the Workflow Object JSON i need to interpolate therefore the whole object JSON is toggled as expression… But some expressions I need to pass as literal text cause the child workflow is the one that needs to do the interpolation there. What happens instead is that the parent workflow attempts to interpolate the expressions and this results in empty text which breaks the child workflow.
Apparently escaping expressions is not possible in the way it is for example in Ansible or terraform. Is there a way to do it?
I tried:
“={{ $json[‘absurd’] }}”
“={{ $json[‘absurd’] }}”
“=\{\{ $json[‘absurd’] \}\}”
“={{ ‘{’ + ‘{’ + $json["absurd"] + ‘}’ + ‘}’ }}”
‘={{ “{” + “{” + $json[“absurd”] + “}” + “}” }}’

Nothing works!!!

What is the error message (if any)?

Please share your workflow

nothing to share just asking a question.

Share the output returned by the last node

n/a

Information on your n8n setup

  • n8n version: 2.12.2
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Amazon Linux 2023

I have used this expression before to receive a literal string of an expression:

{{ '{' + '{' + '$json.data.item' + '}' + '}' }}

Make sure the input field in your editor is set to “Expression” to make it work!

1 Like

Hi @grumpper Welcome!
I recommend using a code node before updating the workflow node is placed, so that the workflow JSON can be built as a javascript plain string with something like JSON.stringify()

1 Like

This kinda worked but with the following adjustment:

In the first opening bracket you have to put also an equal sign so the child workflow knows this is expression. Otherwise it threats it as simple text.

Also if you refer to a key from an item via square brackets you have to make sure to escape the single quotes also.

So at the end to conclude:

To update a workflow using json where some expressions need to be interpolated and other passed as literal text this is the basic syntax:

{
  "interpolated_key": "{{ $json['interpolate_me'] }}",
  "literal_key": "{{ '={' + '{' + '$json[\'pass_me_as_literal\']' + '}' + '}' }}"
}
1 Like

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