title: Filter JSON based of path and regex
body: <p>I want to be able to have a user be able to specify a path and a valid regex and return a filtered JSON based on that. </p>
  
  <p>I think I almost have my solution except that I don't know how to dynamically get the results of a path. Here's my code:</p>
  
  <pre><code>function getResult(jsonObject, pathText, regexToCheck) {
      var pathArr = pathText.split(".")
      var jsonPath = ''
      console.log('start...')
      for(var key in pathArr){
          var addPath = "['"+ pathArr[key] +"']"
          jsonPath += addPath
      }
      result = jsonObject[jsonPath]
      return result.match(new RegExp(regexToCheck, 'g'), match)
  }
  
  function filterBy (json, path, regexToCheck){
      var parseJSON = json
      var filterResult = [];
      for(var obj in parseJSON){
          var result = getResult(parseJSON[obj], path, regexToCheck)
          console.log(result)
          if (result == true){
              filteredResult.push(parseJSON[obj])
          }
      }
      return filterResult
  }
  
  filterBy(json, path, regexToCheck)
  </code></pre>
  
  <p>What I would like like previously mentioned is have a user specify a path and regex like <code>var path = 'configurationId.id'</code> and <code>var regexToCheck = /^[4]/</code> and given the test data below </p>
  
  <pre><code>var json = [{
      "configurationId": {
        "id": "7000",
        "displayName": "7000",
        "uri": "/configuration/users/7000"
      },
      "licenseProperties": {
        "hasClientAccess": true
      },
      "roles": {
        "actualValue": [{
            "id": "Agent",
            "displayName": "Agent",
            "uri": "/configuration/roles/Agent"
          },
          {
            "id": "SMS",
            "displayName": "SMS",
            "uri": "/configuration/roles/SMS"
          }
        ]
      }
    }, {
      "configurationId": {
        "id": "7001",
        "displayName": "7001",
        "uri": "/configuration/users/7001"
      },
      "licenseProperties": {
        "hasClientAccess": true
      },
      "roles": {
        "actualValue": [{
            "id": "Agent",
            "displayName": "Agent",
            "uri": "/configuration/roles/Agent"
          },
          {
            "id": "SMS",
            "displayName": "SMS",
            "uri": "/configuration/roles/SMS"
          }
        ]
      }
    }, {
      "configurationId": {
        "id": "7002",
        "displayName": "7002",
        "uri": "/configuration/users/7002"
      },
      "licenseProperties": {
        "hasClientAccess": true
      },
      "roles": {
        "actualValue": [{
            "id": "Agent",
            "displayName": "Agent",
            "uri": "/configuration/roles/Agent"
          },
          {
            "id": "SMS",
            "displayName": "SMS",
            "uri": "/configuration/roles/SMS"
          }
        ]
      }
    }, {
      "configurationId": {
        "id": "4003",
        "displayName": "4003",
        "uri": "/configuration/users/4003"
      },
      "licenseProperties": {
        "hasClientAccess": true
      },
      "roles": {
        "actualValue": [{
            "id": "Agent",
            "displayName": "Agent",
            "uri": "/configuration/roles/Agent"
          },
          {
            "id": "SMS",
            "displayName": "SMS",
            "uri": "/configuration/roles/SMS"
          }
        ]
      }
    }];
  </code></pre>
  
  <p>Have the result return back,</p>
  
  <pre><code>{
      "configurationId": {
        "id": "4003",
        "displayName": "4003",
        "uri": "/configuration/users/4003"
      },
      "licenseProperties": {
        "hasClientAccess": true
      },
      "roles": {
        "actualValue": [{
            "id": "Agent",
            "displayName": "Agent",
            "uri": "/configuration/roles/Agent"
          },
          {
            "id": "SMS",
            "displayName": "SMS",
            "uri": "/configuration/roles/SMS"
          }
        ]
      }
  </code></pre>
  
  <p>Since my regex just checks to see if the id starts with 4. It's also important to note that this has to work with nested JSONs hence the path specification. So, to re-iterate the place my code fails is essentially here: <code>result = jsonObject[jsonPath]</code></p>