Use Python and JSON to recursively get all keys associated with a value
<p>Giving data organized in JSON format (code example bellow) how can we get the path of keys and sub-keys associated with a given value?</p>

<p>i.e.</p>

<p>Giving an input "23314" we need to return a list with:
Fanerozoico, Cenozoico, Quaternario, Pleistocenico, Superior.</p>

<p>Since data is a json file, using python and json lib we had decoded it:</p>

<pre><code>import json

def decode_crono(crono_file):
    with open(crono_file) as json_file:
        data = json.load(json_file)
</code></pre>

<p>Now on we do not know how to treat it in a way to get what we need.
We can access keys like this:</p>

<p>k = data["Fanerozoico"]["Cenozoico"]["Quaternario "]["Pleistocenico "].<strong>keys()</strong> </p>

<p>or values like this:</p>

<p>v= data["Fanerozoico"]["Cenozoico"]["Quaternario "]["Pleistocenico "]["Superior"].<strong>values()</strong></p>

<p>but this is still far from what we need.</p>

<pre><code>{
"Fanerozoico": {
    "id": "20000",
    "Cenozoico": {
        "id": "23000",
        "Quaternario": {
            "id": "23300",
            "Pleistocenico": {
                "id": "23310",
                "Superior": {
                    "id": "23314"
                },
                "Medio": {
                    "id": "23313"
                },
                "Calabriano": {
                    "id": "23312"
                },
                "Gelasiano": {
                    "id": "23311"
                }
            }
        }
    }
}
}
</code></pre>