insomnia
insomnia copied to clipboard
Fixes #2241 by adding a JSON Linting CodeMirror helper that renders the contents before linting
changelog(Fixes): Fixed an issue where certain template tags would result in JSON Parse error when used as number
Closes #2241 by adding a JSON linting helper to CodeMirror that renders the contents before linting.
Previously, we could not use the Unix timestamp template as an unquoted value, or Faker Date or Faker JSON template due to the JSON linter expecting the values to be quoted.
With this PR, we are attempting to render the nunjuck template values before linting JSON objects. This enables us to validly use the template objects ...
... but still errors appropriately:
~Note, this still broken in the Environment editor, primarily due to the handling of ordering the JSON keys. Will have to address in a future PR.~
Should not be an issue in the Environment editor when used in conjunction with the JSONPath
filter.
Thanks so much @filfreire !
I did have a question though, I was hoping you could help address.
As I mentioned in my OP, I noticed that this functionality is still broken in the Environments configuration due to the way we parse the environment data as JSON to turn it into an ordered object list. Since my current use case is to support this functionality (i.e., use an unquoted value of a template tag as the value for an environment key), such as:
{
"foo": {% response 'body', 'req_2de2c09314934ffbb491cdbb91c3becb', 'b64::JA==::46b', 'never', 60 %}
}
where the response body returns something like:
{
"hello": [
"world",
"kitty",
"barbie",
"my name is inigo montoya"
],
"goodbye": [
"world",
"everyone",
"forever"
]
}
so I can reference in my requests _.foo.hello[0]
to return the value of world
.
I was thinking about pre-parsing the data inside the getValue()
and serializing "foo": {% response 'body', 'req_2de2c09314934ffbb491cdbb91c3becb', 'b64::JA==::46b', 'never', 60 %}
into something more parsable by JSON.parse()
like:
"foo": {
"%": "response 'body', 'req_2de2c09314934ffbb491cdbb91c3becb', 'b64::JA==::46b', 'never', 60"
}
but then we have to add extra logic to deserialize from that output. Seems to get messy. Thoughts?
Thanks so much @filfreire !
I did have a question though, I was hoping you could help address.
As I mentioned in my OP, I noticed that this functionality is still broken in the Environments configuration due to the way we parse the environment data as JSON to turn it into an ordered object list. Since my current use case is to support this functionality (i.e., use an unquoted value of a template tag as the value for an environment key), such as:
{ "foo": {% response 'body', 'req_2de2c09314934ffbb491cdbb91c3becb', 'b64::JA==::46b', 'never', 60 %} }
where the response body returns something like:
{ "hello": [ "world", "kitty", "barbie", "my name is inigo montoya" ], "goodbye": [ "world", "everyone", "forever" ] }
so I can reference in my requests
_.foo.hello[0]
to return the value ofworld
.I was thinking about pre-parsing the data inside the
getValue()
and serializing"foo": {% response 'body', 'req_2de2c09314934ffbb491cdbb91c3becb', 'b64::JA==::46b', 'never', 60 %}
into something more parsable byJSON.parse()
like:"foo": { "%": "response 'body', 'req_2de2c09314934ffbb491cdbb91c3becb', 'b64::JA==::46b', 'never', 60" }
but then we have to add extra logic to deserialize from that output. Seems to get messy. Thoughts?
Looks like this is not a concern after further investigations. I can just set the json response to a quoted variable, and then use the JSONPath
Template filter to pull out the data I need in my requests.
The changes in this PR are still very necessary! Please let me know what else I can do to get this merged in.
@marckong any chance we can get a review from the team on this? Would love to get this in the upcoming release. :)
Fyi, still waiting for this to be pulled in to address an issue I've got opened in my Insomnia Plugin for Faker: https://github.com/bbbco/insomnia-plugin-faker/issues/12 Someone else just commented today on the issue agreeing that this is blocking to them. Would be great to see this fix in the next version of Insomnia!
Can we get this merged in please? This will fix a few issues we're having.
@bbbco this will be merged and hopefull will go out in the next beta release iteration