Add Json stored in a variable to a request body

Hi all!

I been trying to find a way to store a json in a variable in a GET request, store it in a collection variable and use it in a POST request in a collection run.
So far, I been able to store it with no issues in the GET request, but having issues to post it correctly.

I tried using:
“{{MyJsonVar}}”, [{{MyJsonVar}}], ["{{MyJsonVar}}"], {{MyJsonVar}} and still no luck. Is there anything I’m missing? Any help would be greatly appreciated!

Cheers!

Hey @NRS, could you share more details on the exact structure of your requests and json value? Feel free to redact sensitive information :smile:

Yes of course! So the structure goes like this:
image

The GET request have this in the tests:

try{
    // parse Json response object
    let result = JSON.parse(responseBody);
    
    let existingJobId = result.id;
    
    let customFields = result.properties;
    console.log('Original Job bag custom fields: ' + customFields);
    let stringifiedCustomFields = JSON.stringify(customFields);
    console.log('stringified custom fields: ' + stringifiedCustomFields);
    
    // make sure we clean up any previous values.
    pm.variables.unset("properties");
    
    tests["Job Bag Exists"] = existingJobId !== null;
    tests["Has custom fields"] = customFields !== null;
    
    pm.variables.set("job_id", existingJobId);
    pm.variables.set("properties", stringifiedCustomFields);

    }catch(e){
        console.log('Error parsing JSON: ' + e);
    }
    
    postman.setNextRequest('DuplicateJobBag');

Then in the POST body, I have this:

{
	"CopyFromId": {{job_id}},
	"Name": "{{next_job_name}}",
	"CompletionDate": "02/02/2011",
	"Properties": "{{properties}}"
}

properties is a variable in the collection and is the JSON i need to send in the duplicate request.
Sadly, is sending that as null.

Cheers!