title: jq sort using the value of a nested array element
body: <p>I need some help using <code>jq</code> to sort an array of elements where each element contains a nested 
  <code>tags</code> array of elements. My input JSON looks like this:</p>
  
  <pre><code>{
    "result": [
      {
        "name": "ct-1",
        "tags": [
          {
            "key": "service_name",
            "value": "BaseCT"
          },
          {
            "key": "sequence",
            "value": "bb"
          }
        ]
      },
      {
        "name": "ct-2",
        "tags": [
          {
            "key": "service_name",
            "value": "BaseCT"
          },
          {
            "key": "sequence",
            "value": "aa"
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>I would like to sort using the value of the <code>sequence</code> tag in the nested <code>tags</code> array so that the output looks like this:</p>
  
  <pre><code>{
    "result": [
      {
        "name": "ct-2",
        "tags": [
          {
            "key": "service_name",
            "value": "BaseCT"
          },
          {
            "key": "sequence",
            "value": "aa"
          }
        ]
      },
      {
        "name": "ct-1",
        "tags": [
          {
            "key": "service_name",
            "value": "BaseCT"
          },
          {
            "key": "sequence",
            "value": "bb"
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>I have tried the following <code>jq</code> command:</p>
  
  <pre><code>$ jq '.result |= ([.[] | .tags[] | select(.key == "sequence") | .value] | sort_by(.))' input.json
  </code></pre>
  
  <p>but I get the following result:</p>
  
  <pre><code>{
    "result": [
      "aa",
      "bb"
     ]
  }
  </code></pre>
  
  <p>Please let me know if you know how to deal with this scenario.</p>