How to store a JSON in a variable and use it in the request body?

Yes it’s very much possible if you use environment variables.
While creating a mock you can choose the environment from the dropdown, and now keep storing your response JSON to this environment variable (remember to stringify it).

For eg: In your request you can do something like this:

let mockResponse = JSON.stringify(pm.response.json());
pm.environment.set('mockResponse', mockResponse);

And in your response body (make sure it’s type: raw) of the example you’ve to write something like this:

{{mockResponse}}

This variable will be resolved using the environment variable’s value every time you call it.

1 Like