cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Creating JSON adds in the word "array": [] before the data?

SOLVED
Level 6

Creating JSON adds in the word "array": [] before the data?

Hello, so I have ran into a strange issue with Thingworx and creating a JSON object.  

 

The variable sub comes out as an info table, and the JSON goes into the object fine (I can see it when I stringify in the logger).  The problem is that if I call that method and put that JSON object inside another JSON object it will come out as "array": [  all of the correct data in here ]  my problem is that when I pass that to my extension that handles the JSON I get a "JavaException: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token_ at " with that section of the JSON to follow.

 

I am not sure why it is attaching that array word, any assistance to get this to go away would be appreciated.  If I manually remove that "array" word and its brackets that it adds in, it works fine, and I am not sure why it is adding it.

 

CODE:

var holder = [];
var tableLength = sub.rows.length;


for (var x = 0; x < tableLength; x++) {
var row = sub.rows[x];
holder.push({"Name":row.Name,"DateOfBirth":row.DoB,"PhoneNumber":row.Phone});
}

logger.debug("Holder: " + JSON.stringify(holder));
var result = holder;

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Creating JSON adds in the word "array": [] before the data?

I have figured it out.  If you put holder.array that will remove the word "array" and will create the correct JSON syntax.

 

I figured I would post the solution in case anyone else runs into this issue.

2 REPLIES 2

Re: Creating JSON adds in the word "array": [] before the data?

I will look into this and will let you know.

Highlighted

Re: Creating JSON adds in the word "array": [] before the data?

I have figured it out.  If you put holder.array that will remove the word "array" and will create the correct JSON syntax.

 

I figured I would post the solution in case anyone else runs into this issue.