How to send JSON object as JSON String with Postman?
Try this :
{
"User" : {
"userId" : "11111",
"userPropertiesAsJsonString" : "{\"properties\" : {\"propertyName\" : \"test\",\"propertyDesc\" : \"desc\"}}"
}
}
pre-request script:
let query = {}
pm.environment.set('query', JSON.stringify(query));
body:
{{query}}
Jason Mullings' answer did not work for me, but it was an excellent base that allowed me to come up with a solution to a problem very similar to yours.
In the Pre-request Script tab,
const userPropertiesAsJsonString = {
"properties" : {
"propertyName" : "test",
"propertyDesc" : "desc"
}
}
pm.environment.set(
'userPropertiesAsJsonString',
JSON.stringify(JSON.stringify(userPropertiesAsJsonString))
);
Then, in the Body tab,
{
"User" : {
"userId" : "11111",
"userPropertiesAsJsonString" : {{userPropertiesAsJsonString}}
}
}
Stringifying the userPropertiesAsJsonString
variable twice will allow you to escape the JSON string (solution obtained from this answer; refer to this gist for a more detailed explanation) which will then allow you to obtain a request body that looks like the one in the answer provided by sanatsathyan.