How can I update variable values in json body of a request

My request body is a JSON with a list of events. Each event has an eventId and timestamp and it looks like this:
“event”: [
“eid”: 1,
“time”: 1538157934251
“eid”: 2,
“time”: 1538157945251

“eid”: 50,
“time”: 1538157955251

I want to have ‘eid’ and ‘time’ increment for every event using two variables like…

[ {
“eid”: {{id}}+1,
“time”: {{t}}+1000
}, {
“eid”: {{id}}+2,
“time”: {{t}}+5000

“eid”: {{id}}+n,
“time”: {{t}}+n*1000
I was able to do it with Jmeter. Can I do this with postman?

This is how i did it in Jmeter:
“time”:{__longSum({t},1000, t)}.
For those who are not familiar with Jmeter, the above line adds 1000 to t and stores it back to t


For time you can use “moment” in your Pre-request scripts.


//Set Time
var moment = require(“moment”);
var t = pm.variables.get(“t”);
pm.environment.set(‘t’, moment().add(1000, ‘seconds’).valueOf(t));
console.log(“t”, t);

This will pull in your environment variable “t”, add 1000 seconds to the time and then save the it back to the variable “t” to be used in the request.

I have used this in the past with subtracting time to set the timestamp in the past with good success.
Hope this helps.


Hi Mick,

Thanks for the reply. I want the value to get incremented for each event in that JSON. Not for each request. Do you know of any other solution?


Ok, I think I see what you’re trying to do.
See if this works.

In your Pre-Request:

 //Set Time
var moment = require("moment");
var time = moment().valueOf();
pm.environment.set('time', time);

//Set Data
var eventArray = [];_
for(var i = 1; i <= 50; i++) {
    var t = time + (i * 1000);
      "eid": i,
      "time": t

var data = { "event":  eventArray };
var JSONData = new Buffer(JSON.stringify(data)).toString();
pm.environment.set("JSONData", JSONData);
console.log("JSONDATA", JSONData);

Change your entire request body to the following variable:


This is what would be sent:


Thanks a lot Mick. That solves my problem.