Insomnia: [BUG] Template Tag double quotes aren't escaped in JSON

Created on 4 Jul 2018  ยท  8Comments  ยท  Source: Kong/insomnia

  • Insomnia Version: 5.16.6
  • Operating System: Ubuntu 16.04 & Windows 7

Details

If you use a quot (single or double) in a JSONPath in an environment then the json path won't be escaped properly.

For example the JSONPath $.data[?(@.formName=="EOS-Abnahme Protokoll" && @.versionId==69)],
it will translate to
"submitionId": "{% response 'body', 'req_525189fc59f842748426b27683438059', '$.data[?(@.formName=="EOS-Abnahme Protokoll" && @.versionId==69)].submissionId' %}"

Notice the " in the filter. As a workaround, you can change in the preference to the Nunjuck Power User Modus and escape the quots manually, but this requires a restart and it is much more comfortable with the ui (for me at least).

screenshot2

I hope this helps.

  • Sebastian
accepted

Most helpful comment

All 8 comments

๐Ÿ‘‹ Thanks for opening your first issue! If you're reporting a ๐Ÿž bug, please make sure
you include steps to reproduce it. If you're requesting a feature ๐ŸŽ, please provide real
use cases that would benefit. ๐Ÿ‘ช

To help make this a smooth process, please be sure you have first read the
contributing guidelines.

Ah yes, I think this has been reported before. It's a tricky one to fix properly since the tag editor has no concept of the language that it's being used inside of. Different escaping strategies would be needed for every content-type (JSON, XML, etc).

One workaround for now is to use single quotes instead. These will automatically be escaped at the Nunjucks tag level, ending up with something like this:

"{% response 'body', 'req_525189fc59f842748426b27683438059', '$.data[?(@.formName==\'EOS-Abnahme Protokoll\' && @.versionId==69)].submissionId' %}"

Hmm, nvm. Apparently escaped single quotes are not valid JSON either ๐Ÿ˜ฆ

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hi, I faced the same issue: can't use single quotes in JSONPath, like $.data['my-test']

Is there a workaround?

The only workaround I found (haven't checked since I write the issue) is to switch to the Nunjuck Power User Modus in the settings (a restart is required) and escape it manually and then switch back again.

Hi, I faced the same issue: can't use single quotes in JSONPath, like $.data['my-test']

Is there a workaround?

@gschier gave me this workaround, that worked:

{
  "filter": "$['@something']",
  "testing": "{% response 'body', 'req_abc', filter, 'never' %}"
}
Was this page helpful?
0 / 5 - 0 ratings