title: Parsing JSON format with jq
body: <p>I need to parse the output from <code>lsblk</code>. Since I am doing this from within a script I need the output in a standardized format. Therefore I chose the JSON format as output. Here is the command with some sample output:</p>
  
  <pre><code># lsblk -o NAME,MOUNTPOINT -J
  {
     "blockdevices": [
        {"name": "sda", "mountpoint": null,
           "children": [
              {"name": "sda1", "mountpoint": "/sda1/mountpoint"},
              {"name": "sda2", "mountpoint": null,
                 "children": [
                    {"name": "sda2_mapper", "mountpoint": "/sda2/mountpoint"}
                 ]
              },
              {"name": "sda3", "mountpoint": null},
              {"name": "sda4", "mountpoint": null}
           ]
        },
        {"name": "sdb", "mountpoint": null,
           "children": [
              {"name": "sdb1", "mountpoint": "/sdb1/mountpoint"},
              {"name": "sdb2", "mountpoint": null}
           ]
        },
        {"name": "sdc", "mountpoint": null}
     ]
  }
  </code></pre>
  
  <p>I want to extract the names of all <em>innermost</em> nodes, i.e., the name of all nodes that do not have children. The desired output for the above sample would be:</p>
  
  <pre><code>sda1
  sda2_mapper
  sda3
  sda4
  sdb1
  sdb2
  sdc
  </code></pre>
  
  <p>My tool of choice is <code>jq</code> which I have only recently discovered. I have tried</p>
  
  <pre><code># jq '.blockdevices[].children[]?.name?'
  </code></pre>
  
  <p>But this only filters the first level of names. I also tried with</p>
  
  <pre><code># jq 'recurse(.name?)'
  </code></pre>
  
  <p>but this returns the entire file.</p>
  
  <p>Is there a way to return only nodes that do not have children, no matter how deep they are nested?</p>
  
  <p>PS: I am capable of implementing the requirement in <code>bash</code> or <code>awk</code>. I would, however, prefer a solution with a tool like <code>jq</code>, which specific purpose is to parse json files.</p>