title: How do I find a JSON object using a nested expression?
body: <p>From the example JSON below, I would like to return the target.id value of an object where the source.id == 'x'.  </p>
  
  <p>So where source.id == 'startId' return target.id == '3eecd840-e6a8-423c-a892-7df9646fde5d'.</p>
  
  <pre><code>{
        "line":[
           {
              "type":"link",
              "source":{
                 "id":"startId",
                 "port":"out"
              },
              "target":{
                 "id":"3eecd840-e6a8-423c-a892-7df9646fde5d",
                 "port":"in"
              },
              "id":"87d88a26-3a28-4db0-8016-71c1c4665f14"
  
           },
           {
              "type":"link",
              "source":{
                 "id":"3eecd840-e6a8-423c-a892-7df9646fde5d",
                 "port":"outYes"
              },
              "target":{
                 "id":"49940c02-70f2-4c53-ab50-9cbf96903600",
                 "port":"in"
              },
              "id":"9f8c365e-9ca7-440f-a722-c4f340782c0c"
           }
        ]
     }
  </code></pre>
  
  <p>I've tried JSONPath, but I cannot work out the expression to use.  $.line[*].source.id gives me a list of source id's and $.line[?(@.source.id=='startId')] returns an error.</p>
  
  <p>I also understand that I could iterate through each object in code, but It wouldn't be very efficient if I have tens or hundreds of 'lines' to work through.  If possible I would like a more 'direct' path to the object.</p>
  
  <p>I'm using javascript to code the rest of the app, so javascript examples would be helpful (with or without JSONPath).</p>