title: Recursive extraction of object values and parent key name using jq
body: <p>I have a requirement to parse the output of the <code>npm ls --global --json</code> command, such that I get a list of all the installed <code>npm</code> packages in the following format:</p>
  
  <p><code>$package;$version;js;$resolved</code></p>
  
  <p>Where:</p>
  
  <ul>
  <li><code>$package</code> is the key containing the package name, from each <code>dependencies</code> object.</li>
  <li><code>$version</code> is the <code>version</code> value taken from each package</li>
  <li><code>js</code> is just a literal string</li>
  <li><code>$resolved</code> is the <code>resolved</code> value taken from each package</li>
  </ul>
  
  <p>I have gotten as far as this command syntax and output:</p>
  
  <pre><code>$ jq --raw-output 'select( has("dependencies") ) .dependencies[] | . as $d | "parentkey" + ";" + $d.version + ";js;" + $d.resolved'`
  parentkey;5.5.1;js;
  parentkey;1.1.3;js;https://registry.npmjs.org/yaml-table/-/yaml-table-1.1.3.tgz
  </code></pre>
  
  <p>The parts that I am specificly having difficulty with are as follows:</p>
  
  <ul>
  <li><p>How can I get the key name value that I am iterating over in <code>.dependencies</code> that contains that package name. It seems that by that point I am looking at the contents of that object itself.</p></li>
  <li><p>How can I recurse through ALL dependency objects? At the moment I'm only looking at the top level records in the root <code>.dependencies</code> object. I've discovered <code>..</code> recursion, but I'm not quite sure how to apply it here.</p></li>
  </ul>
  
  <p>Based on the example data below, I am trying to reach the following output results:</p>
  
  <pre><code>npm;5.5.1;js;
  JSONStream;1.3.1;js;https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz
  jsonparse;1.3.1;js;https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz
  through;2.3.8;js;https://registry.npmjs.org/through/-/through-2.3.8.tgz
  yaml-table;1.1.3;js;https://registry.npmjs.org/yaml-table/-/yaml-table-1.1.3.tgz
  js-yaml;3.4.6;js;https://registry.npmjs.org/js-yaml/-/js-yaml-3.4.6.tgz
  argparse;1.0.9;js;https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz
  </code></pre>
  
  <p>Some (much reduced) sample output <code>npm ls --global --json</code> that I have used for the above example, is as follows:</p>
  
  <pre><code>{
    "dependencies": {
      "npm": {
        "version": "5.5.1",
        "dependencies": {
          "JSONStream": {
            "version": "1.3.1",
            "from": "JSONStream@~1.3.1",
            "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz",
            "dependencies": {
              "jsonparse": {
                "version": "1.3.1",
                "from": "jsonparse@^1.2.0",
                "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz"
              },
              "through": {
                "version": "2.3.8",
                "from": "through@&gt;=2.2.7 &lt;3",
                "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz"
              }
            }
          }
        }
      },
      "yaml-table": {
        "version": "1.1.3",
        "from": "yaml-table@latest",
        "resolved": "https://registry.npmjs.org/yaml-table/-/yaml-table-1.1.3.tgz",
        "dependencies": {
          "js-yaml": {
            "version": "3.4.6",
            "from": "js-yaml@3.4.6",
            "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.4.6.tgz",
            "dependencies": {
              "argparse": {
                "version": "1.0.9",
                "from": "argparse@&gt;=1.0.2 &lt;2.0.0",
                "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz"
              }
            }
          }
        }
      }
    }
  }
  </code></pre>