1

my code looks like this:

"Control Statements": [
            {
                "key": " {% for foo in foo1 %} ... {% endfor %}",
                "val": "For loop"
            },
            {
                "key": "{% foo %} ... {% endif %}",
                "val": "If statement"
            }
         ]

I want to escape curly braces in the "key part"

AYUSH KUMAR
  • 67
  • 1
  • 10
  • Can you clarify this question? Are these getting rendered in a template? What have you tried so far? – dizzyf Nov 16 '16 at 17:01
  • yes it is to be rendered.. i have got my answer. it worked well using \\ before "{" and "}". `"key": " \\{% foo %\\}...\\{% endif %//}` – AYUSH KUMAR Nov 16 '16 at 18:53
  • 1
    @AYUSHKUMAR Can you please edit your question to clarify this, instead of through a comment? The answer you stated doesn't appear here. So can you please also add an answer and mark it as a solution? Stack Overflow isn't just a site for you to solve your problem and move on. It's a community where everyone helps each other to learn. – falsePockets Aug 30 '19 at 03:18

3 Answers3

2

It works using \\ before "{" and "}".

eg:

"key": " \\{% foo %\\}...\\{% endif %//}

AYUSH KUMAR
  • 67
  • 1
  • 10
0

You escape json braces { } by adding additional ones {{ }}. I assume you could some online utility to help you escape json characters easily.

Alaa
  • 393
  • 1
  • 2
  • 10
  • What do you mean? If my template looks like `{{ foo }}`, and I want the output to be literally `{{ foo }}`, do I do `{{ { }}{{ { }} foo {{ } }}{{ } }}`? – falsePockets Aug 30 '19 at 03:14
0

Use "\uXXXX" notation for any character you want instead of XXXX you need to put hexadecimal unicode code of character.

<{> has code 0x7b and <}> is 0x7d. So "\u007b" and "\u007d"

Alexander C
  • 3,597
  • 1
  • 23
  • 39
  • That didn't work for me. The output is still `\u00xx`, instead of `{` and `}`. Jinja didn't convert those characters into curly braces. – falsePockets Aug 30 '19 at 03:15