How can I iterate through this JSON object using javascript

advertisements

This question already has an answer here:

  • Access / process (nested) objects, arrays or JSON 15 answers

How do I pull out ColumnValues[i] using javascript from this JSON sample using two instances with keys = "1" and "2" as shown below. This is just a sample my original JSON object has 500+ entries like this with key = "1", "2", "3", "4", etc. When I retrieve the length of the object the value that is returned equals 1 so using for loop does not work with the length property. Appreciate any help.

JSON object below

[
 {
    "1": {
        "ChildCount": 0,
        "ColumnIndentLevel": 0,
        "DescendantCount": 0,
        "IndentLevel": 0,
        "IsCategory": false,
        "IsConflict": false,
        "IsDocument": true,
        "IsTotal": false,
        "IsValid": true,
        "NoteID": "3962",
        "SiblingCount": 2,
        "UniversalID": "E8D5D7E88B08CBD686257CD6007470E5",
        "ColumnValues": {
            "0": "03297",
            "1": "Amelia Tang",
            "2": "NBK3456",
            "3": "FHA",
            "4": "2008/10/03 00:00:00 UTC-0000",
            "5": "Withdrawn by SASE Administration",
            "6": "Approver Level 2",
            "7": "Reinstatement"
        }
    },
    "2": {
        "ChildCount": 0,
        "ColumnIndentLevel": 0,
        "DescendantCount": 0,
        "IndentLevel": 0,
        "IsCategory": false,
        "IsConflict": false,
        "IsDocument": true,
        "IsTotal": false,
        "IsValid": true,
        "NoteID": "7972",
        "SiblingCount": 2,
        "UniversalID": "4CEE012B8D60A86A86257CD6007657B0",
        "ColumnValues": {
            "0": "20004484",
            "1": "Anthony Susino",
            "2": "",
            "3": "Conventional",
            "4": "2009/05/11 00:00:00 UTC-0000",
            "5": "Withdrawn by SASE Administration",
            "6": "",
            "7": ""
        }
    }
}]


Use this:

for (var key in yourObject) { // key will be "1", "2", ...
    var value = yourObject[key];

    // do something
}