I have a dictionary like this:
I saw this question Find all occurrences of a key in nested python dictionaries and lists, but it's return all the values of key.
{
"html": {
"head": {
"title": {
"text": "Your Title Here"
}
},
"body": {
"bgcolor": "FFFFFF",
"img": {
"src": "clouds.jpg",
"align": "bottom",
"text": ""
},
"a": [
{
"href": "http://somegreatsite.com",
"text": "Link Name"
},
{
"href": "mailto:support@yourcompany.com",
"text": "support@yourcompany.com"
}
],
"p": [
{
"text": "This is a new paragraph!dasda"
},
{
"h1": {
"text": "dasda"
}
}
{
"h3": {
"text": "hello therereere"
}
}
],
"h1": [
{
"text": "This is a Header"
},
{
"class": "text-primary",
"text": "This is a Header"
}
],
"h2": {
"text": "This is a Medium Header"
},
"b": {
"text": "This is a new sentence without a paragraph break, in bold italics.",
"i": {
"text": "This is a new sentence without a paragraph break, in bold italics."
}
}
}
}
}
I want to function just find the first occurrence of key
for example:
if i search for h1
return:
{"text": "dasda"}