> For the complete documentation index, see [llms.txt](https://ressurect.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ressurect.gitbook.io/notes/cheatsheet/json-jq.md).

# JSON - jq

### **# Displaying nested keys:**

This is highly useful when dealing when large JSON structure which can contain multiple nested keys. For instance, if you wanted to know what set of JSON keys lead to a value of 'XYZ', the below command would provide the keys in the format A.B.C=XYZ\
\
*Note: You may encounter integers 0,1,2,etc. This basically indicates the presence of multiple values for the key i.e. Arrays "\[]".*

<pre class="language-bash" data-overflow="wrap"><code class="lang-bash">jq -r 'paths(scalars | true) as $p  | [ ( [ $p[] | tostring ] | join(".") ), ( getpath($p) | tojson )] | join(": ")' <a data-footnote-ref href="#user-content-fn-1">&#x3C;json-file></a> > json.paths
</code></pre>

<details>

<summary>Sample Output</summary>

```
glossary.title: "example glossary"
glossary.GlossDiv.title: "S"
glossary.GlossDiv.GlossList.GlossEntry.ID: "SGML"
glossary.GlossDiv.GlossList.GlossEntry.SortAs: "SGML"
glossary.GlossDiv.GlossList.GlossEntry.GlossTerm: "Standard Generalized Markup Language"
glossary.GlossDiv.GlossList.GlossEntry.Acronym: "SGML"
glossary.GlossDiv.GlossList.GlossEntry.Abbrev: "ISO 8879:1986"
glossary.GlossDiv.GlossList.GlossEntry.GlossDef.para: "A meta-markup language, used to create markup languages such as DocBook."
glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso.0: "GML"
glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso.1: "XML"
glossary.GlossDiv.GlossList.GlossEntry.GlossSee: "markup"

```

</details>

[^1]: Path to file containing JSON body
