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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

how to take out the length of the json elements?

adityaku
1-Newbie

how to take out the length of the json elements?

for example:

var text =

{"employees":[

    {"firstName":"John", "lastName":"Doe", "Age":"24", "Gender":"M"},

    {"firstName":"Anna", "lastName":"Smith", "Age":"25", "Gender":"F"},

    {"firstName":"Peter", "lastName":"Jones", "Age":"24", "Gender":"M"},

    {"firstName":"Aditya", "lastName":"Kumar", "Age":"25", "Gender":"M"},

    {"firstName":"Shashank", "lastName":"Rai", "Age":"24", "Gender":"M"},

    {"firstName":"Harshit", "lastName":"Chowdhary", "Age":"24", "Gender":"M"},

    {"firstName":"Reetam", "lastName":"Kansabanik", "Age":"26", "Gender":"M"},

    {"firstName":"Priyanka", "lastName":"Kumari", "Age":"20", "Gender":"F"},

    {"firstName":"Nidhi", "lastName":"Tiwari", "Age":"22", "Gender":"F"},

    {"firstName":"Priyanshu", "lastName":"Mehta", "Age":"23", "Gender":"M"},

    {"firstName":"Preeti", "lastName":"Gupta", "Age":"24", "Gender":"F"},

    {"firstName":"Virat", "lastName":"Kohli", "Age":"28", "Gender":"M"},

    {"firstName":"Mahendra", "lastName":"Dhoni", "Age":"24", "Gender":"M"},

    {"firstName":"Harshita", "lastName":"Rai", "Age":"23", "Gender":"F"},

    {"firstName":"Ishan", "lastName":"Verma", "Age":"24", "Gender":"M"},

    {"firstName":"Moen", "lastName":"Ali", "Age":"24", "Gender":"M"},

    {"firstName":"Muktesh", "lastName":"Chandra", "Age":"32", "Gender":"M"},

    {"firstName":"Vinod", "lastName":"Patel", "Age":"28", "Gender":"M"}

]}

In the above example we have 18 elements, but how take the length of var text in case of JSON elements in thingworx?

3 REPLIES 3

in normal outside thingworx, we use:

Object.keys(text).length;


But this is not working.

Try this. It will do.

var result = text["employees"].length;

Thanks Praveen

Top Tags