I'm trying to prepare a JSON with a certain structure to send over REST. Every 250 events, I want to send a JSON payload with those events. I'm trying to emulate this using the code below, but it is not returning anything.
var eventQueue = new Array();
for (j = 0; j < 251; j++) {
var curr_timestamp = new Date().getTime();
eventQueue.push({
"client_ip" : "127.0.0.1",
"timestamp" : curr_timestamp,
"user_name" : "Robert"
});
if(j = 250) {
var jString = JSON.stringify(eventQueue);
var payload = '{"root":{"user_data":[' + jString + ']}}';
}
}
The JSON payload structure I need to create looks like:
{
"root":{
"user_data":[
{
"client_ip":"127.0.0.1",
"timestamp":"1723452955",
"user_name":"Robert"
},
{
"client_ip":"127.0.0.1",
"timestamp":"1723452956",
"user_name":"Robert"
},
{
"client_ip":"127.0.0.1",
"timestamp":"1723452957",
"user_name":"Robert"
},
...
]
}
}
Should I be using join instead to prepare the structure or is there a better approach?
j = 250is assignment.