title: What are the best ways to reference branches of a JSON tree structure?
body: <p>So I've got a JSON file that gets parsed into an object in Javascript. I know what you're thinking: lucky guy. The JSON is essentially a flow diagram in a big tree form. Here's tiny a sample of what I'm trying to achieve:</p>
  
  <pre><code>tree = {
      "options": [
          {
              "options": [
                  {
                      "name": "target",
                  },
              ],
          },
          {
              "options": [
                  {
                      "link": "...?",
                  },
              ],
          },
      ]
  }
  </code></pre>
  
  <p>So in this example, I'll be deep in the second branch (where it says <code>"link"</code>) and I'll want to be able to jump to the branch that contains <code>"name": "target"</code>. This is JSON remember so it'll need to be a string (unless there's a native for linking?! is there?) but I don't know how best to format that.</p>
  
  <p>As I see it, I've got at least a couple of options.</p>
  
  <ol>
  <li><p>I could search. If <code>name</code> was unique, I could scale the tree looking for elements until I found it. I've never done with with Javascript before but I expect it to be slow.</p></li>
  <li><p>I could use a navigation path like <code>options:1:options:1</code> that describes each key for the path. Again, I've never done this but, assuming there are no errors, it would be a lot faster. How would you implement it?</p></li>
  </ol>
  
  <p>Are there any other options available to me? What seems best? Is there a way to unpack this when JSON decoding, or is that a recipe for an infinite loop?</p>