This plugin enhances functionality of the built-in JSONPath plugin by adding ability to pass JSON object on top of existing functionality that allows string input only.
The plugin treats all visible environment variables as branches of a tree that in turn represent sub-trees on their owns. For example, consider the following list of environment variables defined on the global scope:
"users": {
"dev": {
"user_a:": {
"email": "[email protected]",
"password": "abc123"
},
"user_b:": {
"email": "[email protected]",
"password": "123abc"
}
},
"prod": {
"user_c:": {
"email": "[email protected]",
"password": "xyz321"
},
"user_d:": "{ \"email\": \"[email protected]\", \"password\": \"321xyz\" }"
}
}
and two sub-environments dev
and prod
with the following lists of defined environment variables:
{
"env": "dev",
"user": "{% jsonpathpp 'users.dev.user_a' %}" ,
"email": "{% jsonpathpp 'user.email' %}",
"password": "{% jsonpathpp 'user.password' %}"
}
and
{
"env": "prod",
"user": "{% jsonpathpp 'users.prod.user_c' %}",
"email": "{% jsonpathpp 'user.email' %}",
"password": "{% jsonpathpp 'user.password' %}"
}
with jsonpathpp
being plugin's template tag to be, for example, displayed as users.prod.user_c'
in case of definition {% jsonpathpp 'users.prod.user_c' %}
Please note that users.prod.user_d
in global scope is defined as a parseable JSON string which will be internally parsed and replaced as:
{
"email": "[email protected]",
"password": "321xyz"
}
Then, for example, you might have a login request that takes JSON object for user credentials, so we can populate request body as
{
"email": "{% jsonpathpp 'email' %}",
"password": "{% jsonpathpp 'password' %}"
}
which will be automatically substituted with correct values when you switch between dev
and prod
sub-environments.
This plugin is nothing more but a wrapper to existing functionality. Its ultimate goal is to add some convenience to the process of switching between sub-environments and selecting proper subset of values inside selected sub-environment (in our above example, switching of a current dev
user can be achieved be replacing value of user
variable from {% jsonpathpp 'users.dev.user_a' %}
to {% jsonpathpp 'users.dev.user_b' %}
in tag editor UI).
Under the hood this plugin uses JSONPath NPM module for processing of provided JSONPath. As a fun exercise reward yourself by playing with The Store example that you can copy over into Insomnia environment from module README file.