title: Python - Return path of all JSON elements that match string
body: <p>I'm trying to logically traverse a JSON in Python and return the path of any String value that equals a value. I'm trying to traverse it recursively, but if multiple elements match the comparison, it only returns he first:</p>
  
  <pre><code>test_json = {
      "a": {
          "b": {
              "c": {
                  "d": "foo"
              }
          }
      },
      "1": {
          "2": {
              "3": "bar"
          }
      },
      "a1" : "foo"
  }
  
  def searchDict(d, path):
      for k,v in d.iteritems():
          if isinstance(v, dict):
              path.append(k)
              return searchDict(v, path)
          else:
              if v == "foo":
                  path.append(k)
                  path.append(v)
                  return path
  
  print searchDict(test_json, [])
  </code></pre>
  
  <p>I want this to have the capacity to return something like:</p>
  
  <pre><code>a -&gt; b -&gt; c -&gt; d -&gt; foo
  a1 -&gt; foo
  </code></pre>
  
  <p>But instead it only iterates through the first sub-dictionary:</p>
  
  <pre><code>['a', 'b', 'c', 'd', 'foo']
  </code></pre>
  
  <p>This is probably easier than I'm making it, just having trouble logically solving it. Any ideas?</p>