Thingworx output JSON error if output populate with push

216 Views Asked by At

I have an object to response but It has an array to add multiple object into this inside array, you can see in below. The problem is if this inside array populate with push or something else Thingworx is stop running.

Response structure:

var last = {
    plans: []
};

Populating this object:

last.plans[0] = Inputs.offers[1]; 
OR
last.plans.push(Inputs.offers[1]);

If I want to return last Thingworx is stop working.

But if return like this;

var result = Inputs.offers[1];

It's return well. What if more than 1 result in it. I used push into array that reason.

By the way, output type is JSON.

2

There are 2 best solutions below

1
Carles Coll On

Strange should work, when you mean return last, you mean:

var result = last;

And when you say "stop working" what does you mean? which error message do you get?

0
Yasin Yörük On

Ok, Find a solution at the end. Fixed. This is the final code block.

var last = {
    plans: []
};
var offer = JSON.parse(offers[0]);
last.plans.push(offer);

JSON.parseis my solution. offers[0] is already json object. I'm not sure why thingworx needs to parse this structor.