At times the elements contained in a JSON object or infortable (which is a JSON object) may be variable or unknown.  Here is some simple sample code to help loop through an object and extract the names of the elements, as well as the values and types...


var myJson = {"element1": "hello",

                         "element2": 12,

                         "element3": true,

                         "element4": {"subelement1": "one",

                                                  "sebelement2": 2}



for (var el in myJson) {

     //output each to the thingworx script log

    logger.warn("Element name: " + el + ", element value: " + myJson[el] + ", element type: " + typeof(myJson[el]));

     //you can add logic to parse and nested objects (like element4) here




The script log output would show...

"Element name: element1, element value: hello, element type: String"

"Element name: element2, element value: 12, element type: Number"

"Element name: element3, element value: true, element type: Boolean"

"Element name: element4, element value: [object], element type: Object"