Using json data files to store environment variables

I have seen numerous articles about using json data files and using environment variables, but not on using a specific json file per environment.

Also, if you need to store variables for multiple tests in your collection in that csv, how do you best structure the json file for that?

1 Like

To use environments from a file, you need to use Newman.

You don’t manually create the environments, you export them from Postman.

Hi @imageekgirl,

In addition to what @vdespa noted, you can create a json string, store thats string as an environment variable, and when you need to use that json string to modify it, you can parse that JSON in your test pre-request script using JSON.parse(pm.environment.get("jsonString")), to which it should act like native JSON, where you can add, remove, or modify JSON attributes and values, and then save it back to your postman variable like so: pm.environment.set("jsonString", JSON.stringify(yourJSONvariable)) which should persist it for the next request.

Then repeat this process for any future requests that need this JSON.

Best,
Orest

1 Like

What i’m trying to do is set this up so I have a json file of data applicable to environment1 and another applicable to environment2, and so on. For various reasons my management does not want do tests with mocking or setup/teardown, and as I’m running my tests, I need to be able to assert not just that a value exists but that the correct value (which I’m using variables for so we can make these tests work in any environment by switching which data file is used) is present in the correct field.
I’m working locally and using the collection runner within postman but this will need to run via CI eventually. It seems extremely cumbersome to require using newman just to “test the tests” while I’m working on them?