# Dynamic variable help

**URL:** <https://community.postman.com/t/dynamic-variable-help/20865>\
**Category:** Help Hub\
**Created:** [February 26, 2021, 6:02pm UTC](https://community.postman.com/t/dynamic-variable-help/20865 "2021-02-26T18:02:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cfitzgerald2019](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@cfitzgerald2019](https://community.postman.com/u/cfitzgerald2019)\
**Post date:** [February 26, 2021, 6:02pm UTC](https://community.postman.com/t/dynamic-variable-help/20865/1 "2021-02-26T18:02:01Z")

</div>

Hi. I’m fairly new to Postman and hit a wall. It’s possible I have more than 1 issue so I will try to be as detailed as possible. Please let me know if I don’t include enough info.  
I’m attempting to build a list as a variable using utils in the request level pre-request script and within that utils I’m attempting to set the date/time using $isoTimestamp. When I send the request, the response body I get back is  
{  
“title”: “HttpMessageNotReadableException”,  
“detail”: “Malformed JSON request”  
}  
Here is my request level pre-request script (there are more attributes but I’ve shortened the list for simplicity):  
pm.variables.replaceIn(“{{$isoTimestamp}}”);

var transactionObjectList = [  
utils.buildTransactionObject( {  
payAmount: 0.00,  
transactionId: “transactionId”,  
transactionDateTime: “$isoTimestamp”,  
})  
]

pm.collectionVariables.set(“transactionObjectList”, transactionObjectList);  
pm.collectionVariables.set(“transactionAmount”, 123.45);

and here is the Body:  
{  
“eventSource”: {{pm.request.name}},  
“eventDateTime”: {{$isoTimestamp}},  
“eventObject”: {},  
“transactions”: {{transactionObjectList}}  
}

My 1st question is what is the proper way to use/set $isoTimestamp? (I realize I probably have something extra going on in this code)  
My 2nd question is what causes the Malformed JSON request error and how might I correct that?

\*\*Edit: apologies I left out a part. These requests are in a subfolder so in the pre-request script of that subfolder, I have:  
utils = {  
buildTransactionObject: function({ payAmount = 0.00, transactionId = undefined, transactionDateTime = undefined} = {}) {  
var transactionObject = {};  
transactionObject.payAmount = payAmount;  
transactionObject.transactionId = transactionId;  
transactionObject.transactionDateTime = transactionDateTime;

```
    return transactionObject;
}

```

}

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [February 27, 2021, 1:51pm UTC](https://community.postman.com/t/dynamic-variable-help/20865/2 "2021-02-27T13:51:21Z")

</div>

json accept data types like number, object , array and string.

string should be enclosed with double quotes , single is not supported so

```
{
“eventSource”: "{{pm.request.name}}",
“eventDateTime”: "{{$isoTimestamp}}",
“eventObject”: {},
“transactions”: {{transactionObjectList}}
}

```

if transactionobjectlist is an array or object you don’t need to enclose it with quotes elese you have to

---

<div class="post-metadata">

**Author:** ![cfitzgerald2019](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@cfitzgerald2019](https://community.postman.com/u/cfitzgerald2019)\
**Post date:** [March 1, 2021, 6:07pm UTC](https://community.postman.com/t/dynamic-variable-help/20865/3 "2021-03-01T18:07:09Z")

</div>

thanks. that did help. I was also missing the braces around $isostamp where I call transactionObjectList.  
so, I had  
transactionDateTime: “$isoTimestamp”,  
but it needed to be  
transactionDateTime: “{{$isoTimestamp}}”,  
that resolved the syntax to use $isoTimestamp the way I wanted but I was still getting the Malformed JSON request error. after some experimenting and getting help from a dev, we came up with this which resolved the issue and gave me the success response I was looking for  
pm.collectionVariables.set(“transactionObjectList”, JSON.stringify(transactionObjectList));
