hurl icon indicating copy to clipboard operation
hurl copied to clipboard

Support raw string

Open jcamiel opened this issue 2 years ago • 4 comments

Problem to solve

When using JSON body or multiline string, {{ is interpreted as a variable expansion by Hurl. For instance, this JSON body:

{
  "template": "{{#user~}}I want a response to the following query:{{query}}{{~/user}}"
}

Should be sent either with JSON unicode literal:

POST http://localhost:8000/api/v1/messages
{
  "template": "\u007B\u007B#user~\u007D\u007DI want a response to the following query:\u007B\u007Bquery\u007D\u007D\u007B\u007B~/user\u007D\u007D"
}

or with Hurl unicode literal:

POST http://localhost:8000/api/v1/messages
```json
{
  "template": "\u{7b}\u{7}#user~\u{7D}\u{7D} want a response to the following query:\u{7b}\u{7b}query\u{7d}\u{7d}\u{7d}\u{7d}~/user\u{7d}\u{7d}"
}
```

Proposal

Use "multiline string" with raw hint to disable all variable interpolation.

POST http://localhost:8000/api/v1/messages
```raw
{
  "template": "{{#user~}}I want a response to the following query:{{query}}{{~/user}}"
}
```

jcamiel avatar Jul 06 '23 16:07 jcamiel

What is the current solution to sending {{}} string literals in JSON payloads? I can't make it work...

Regarding the raw proposal, mixed request bodies where I want to evaluate variables but also use literals should be considered, so marking the whole body as either of the two might not be the best solution.

michelkaeser avatar Apr 08 '24 09:04 michelkaeser

Hi @michelkaeser

Can you use JSON unicode literal ({ => \u007B, } => \u007D) ?

POST http://localhost:8000/api/v1/messages
{
  "template": "\u007B\u007B#user~\u007D\u007DI want a response to the following query:\u007B\u007Bquery\u007D\u007D\u007B\u007B~/user\u007D\u007D"
}

As it's a valid JSON compliant string (independant of Hurl format), it should be OK

jcamiel avatar Apr 08 '24 09:04 jcamiel

Related #2428

jcamiel avatar Apr 08 '24 16:04 jcamiel

Hi @michelkaeser

Can you use JSON unicode literal ({ => \u007B, } => \u007D) ?

POST http://localhost:8000/api/v1/messages
{
  "template": "\u007B\u007B#user~\u007D\u007DI want a response to the following query:\u007B\u007Bquery\u007D\u007D\u007B\u007B~/user\u007D\u007D"
}

As it's a valid JSON compliant string (independant of Hurl format), it should be OK

JSON unicode literal worked successfully after all. Many thanks!

michelkaeser avatar Apr 09 '24 20:04 michelkaeser