title: Traversal Algorithm for Recursive JSON Data Structure
body: <p>I'm building a graph editor in Javascript and I need an algorithm to identify all possible routes between two 'node' objects.</p>
  
  <p>Given the following JSON object:</p>
  
  <pre><code>{
      "failureNode": {
          "failureNode": {
              "failureNode": {
                  "failureNode": {
                      "failureNode": null,
                      "successNode": null,
                      "id": "node-endpointfailure",}
                  },
                  "successNode": {
                      "failureNode": null,
                      "successNode": null,
                      "id": "node-endpointsuccess",
                  },
                  "id": "node-1",
              },
              "successNode": {
                  "failureNode": null,
                  "successNode": null,
                  "id": "node-endpointsuccess",
              },
              "id": "node-2",
          },
          "successNode": {
              "failureNode": {
                  "failureNode": {
                      "failureNode": null,
                      "successNode": null,
                      "id": "node-endpointfailure",
                  },
                  "successNode": {
                      "failureNode": null,
                      "successNode": null,
                      "id": "node-endpointsuccess",
                  },
                  "id": "node-1",
              },
              "successNode": {
                  "failureNode": null,
                  "successNode": null,
                  "id": "node-endpointsuccess",
              },
              "id": "node-3",
          },
          "id": "node-4",
      },
      "successNode": {
          "failureNode": null,
          "successNode": null,
          "id": "node-endpointsuccess",
      },
      "id": "node-root",
  }
  </code></pre>
  
  <p>I need all possible routes between nodes with ID = 'node-root' &amp;'node-endpointfailure'. In this example, there are two possible ways to start at 'Start' (which is node-root in the data structure) and end and 'Failure' (node-endpointfailure):</p>
  
  <ol>
  <li>Start -> node1 -> node2 -> node4 -> failure</li>
  <li>Start -> node1 -> node3 -> node4 -> failure</li>
  </ol>
  
  <p>For this example, the output would be an array of JSON paths. Something like this...</p>
  
  <pre><code>[
      failureNode.failureNode.failureNode.failureNode,
      failureNode.successNode.failureNode.failureNode
  ]
  </code></pre>
  
  <p>Most of the application is using jQuery, so either a pure Javascript or jQuery solution will work.</p>