I have JSON documents stored in Postgres under the JSON data type (Postgres 9.3) and I need to recursively collect the key names down the tree.
For example, given this JSON tree
{
"files": {
"folder": {
"file1": {
"property": "blah"
},
"file2": {
"property": "blah"
},
"file3": {
"property": "blah"
},
"file4": {
"property": "blah"
}
}
},
"software": {
"apt": {
"package1": {
"version": 1.2
},
"package2": {
"version": 1.2
},
"package3": {
"version": 1.2
},
"package4": {
"version": 1.2
}
}
}
}
I would like to extract something like [file1,file2,file3,file3,package1,package2,package3,package4]
Basically just a listing of keys that I can use for a text search index.
I know I can get a listing of keys on the outer most objects using something like
SELECT DISTINCT(json_object_keys(data))
And I know it's possible to to recursively climb through the tree using something like
WITH RECURSIVE data()
but i'm having trouble putting the two together.
Can anyone help?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…