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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

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

TonyV
7-Bedrock

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;

ACCEPTED SOLUTION

Accepted Solutions
TonyV
7-Bedrock
(To:posipova)

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.

View solution in original post

2 REPLIES 2
posipova
20-Turquoise
(To:TonyV)

I will look into this and will let you know.

TonyV
7-Bedrock
(To:posipova)

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.

Announcements


Top Tags