question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Reference another JSON object as an environment variable

See original GitHub issue
  • Insomnia Version: 5.14.9
  • Operating System: Ubuntu 17.10

Details

When defining base and sub environments you’re unable to dump a raw variable to return a JSON object.

For example, the following environment results in an Unexpected token { in JSON at position 286 error:

{
    "addresses": {
        "home": {
            "line1": "123 E Fake Street",
            "city": "Nowheresville",
            "state": "AL",
            "zip_code": "12345"
        },
        "work": {
            "line1": "123 E Fake Street",
            "city": "Nowheresville",
            "state": "AL",
            "zip_code": "12345"
        }
    },
    "people": {
        "name": "John Pinkerton",
        "phone_number": "123-456-7890",
        "address": {{ addresses.home | dump }}        
    }
}

The problem is specific to the {{ addresses.home | dump }} variable. I don’t get the error if I surround the variable in quotes but then it is treated as a string instead of an object. The same variable works fine in a request body.

EDIT: If it wasn’t obvious the expected behavior is that {{ addresses.home | dump }} would parse out to the full JSON object:

{
    "line1": "123 E Fake Street",
    "city": "Nowheresville",
    "state": "AL",
    "zip_code": "12345"
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gschiercommented, Mar 8, 2018

I see. Thanks for the example 😄

At this moment, plugins aren’t able to modify the environment (only read it). But, if this functionality were added, you could write a simple plugin that looked at your environment and built these objects for you.

For example:

"combos": {
       "cheeseburger_combo": ["cheeseburger", "french_fries", "fountain_drink"]
}

Then, a plugin could look through the array and replace the cheeseburger_combo array with the full-constructed object before the request is made.

Just an idea for the future.

1reaction
gschiercommented, Mar 6, 2018

FYI, I Just published the plugin under insomnia-plugin-jsonpath if you want to try it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Request] Reference another JSON object as ... - GitHub
The reason that it doesn't work currently is that the environment is stored as a JSON object on the database model and request...
Read more >
Proper Ways to Pass Environment Variables in JSON for ...
TL;DR. The best practice is using a data generation function. Scrolling to the bottom for the detail. Setup a mock API server for...
Read more >
How to work with JSON objects and variables in Postman
Hey guys, in this short live video I wanted to show you how you can work with objects and variables in Postman.
Read more >
JSON Reference — JSON Spec documentation - Read the Docs
JSON Reference allows a JSON value to reference another value in a JSON document. This module implements utilities for exploring these objects.
Read more >
How to include an environment variable in a json file?
Simply define the profile value to be relative to the user's home directory if it is not an absolute path. But really, you've...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found