title: Using underscore.js to find values in deeply nested JSON
body: <p>I'm pretty new to Javascript, and I just learned about underscore.js.  I have a deeply nested JSON object, and I need to use underscore to find key/value pairs, which I will then use to populate various HTML tables.  If the structure was more shallow, using something like _.pluck would be easy, but I just don't know how to traverse past the first couple of nesting levels (i.e. surveyGDB, table, tablenames). The JSON object comes from an XML that is comprised of multiple nesting structures (mashed up from different database tables).</p>
  
  <pre><code>var JSONData = 
  "surveyGDB": {
        "filename": "..\\Topo\\SurveyGeoDatabase.gdb",
        "table": {
          "tablename": [
            {
              "#text": "SurveyInfo\n      ",
              "record": {
                "OBJECTID": "1",
                "SiteID": "CBW05583-345970",
                "Watershed": "John Day",
                "VisitType": "Initial visit",
                "SurveyInstrument": "Total Station",
                "ImportDate": "2015-07-22T09:08:42",
                "StreamName": "Duncan Creek",
                "InstrumentModel": "TopCon Magnet v2.5.1",
                "FieldSeason": "2015"
            }
          },
          {
            "#text": "QaQcPoints\n      ",
            "record": [
              {
                "OBJECTID": "1",
                "TIMESTAMP": "2015-07-22T09:18:43",
                "Code": "tp",
                "Count": "357"
              },
              {
                "OBJECTID": "2",
                "TIMESTAMP": "2015-07-22T09:18:43",
                "Code": "tb",
                "Count": "92"
              },
              {
                "OBJECTID": "3",
                "TIMESTAMP": "2015-07-22T09:18:43",
                "Code": "to",
                "Count": "8"
              },
              {
                "OBJECTID": "4",
                "TIMESTAMP": "2015-07-22T09:18:43",
                "Code": "bl",
                "Count": "279"
              },
              {
                "OBJECTID": "5",
                "TIMESTAMP": "2015-07-22T09:18:43",
                "Code": "bf",
                "Count": "18"
              }
            ]
          },
          {
            "#text": "QaQcPolygons\n      ",
            "record": [
              {
                "OBJECTID": "1",
                "TIMESTAMP": "2015-07-22T09:43:08",
                "SurveyExtentCount": "",
                "WaterExtentCount": "",
                "ChannelUnitsCount": "",
                "ChannelUnitsUnique": ""
              },
              {
                "OBJECTID": "2",
                "TIMESTAMP": "2015-07-22T13:35:15",
                "SurveyExtentCount": "1",
                "WaterExtentCount": "1",
                "ChannelUnitsCount": "21",
                "ChannelUnitsUnique": "21"
              }
            ]
          }
        ]
      }
    }
  }
  </code></pre>
  
  <p>For instance, I wanted all of the values for 'Code' in the 'QaQCPoints' table, so I tried:</p>
  
  <pre><code>var codes = _.flatten(_.pluck(JSONData.surveyGDB.table.tablename[1].record[0], "Code" ));
  console.log(codes);
  </code></pre>
  
  <p>In the console, this returns an array with a length of 5, but with blank values.
  What am I doing wrong?</p>
  
  <p>I'd also rather search for the 'Code' values in the table based on something like the '#text' key value, instead of just using it's position in the object.</p>