I am trying to export data from consul kv to json with a nested object for each depth level in the consul.
An json example returned from the consul:
[ { "LockIndex": 0, "Key": "foobar/testing", "Flags": 0, "Value": "xxxxx", "CreateIndex": 833, "ModifyIndex": 833 }, { "LockIndex": 0, "Key": "foobar/bazbar", "Flags": 0, "Value": "xxxxx", "CreateIndex": 833, "ModifyIndex": 833 } ]
Desired JSON:
[ { "foobar": { "testing": "xxxxx", "bazbar": "xxxxx" } } ]
I'm kinda close to jq '.[] | objects | {Key: .Key | split("/"), Value: .Value}' jq '.[] | objects | {Key: .Key | split("/"), Value: .Value}' jq '.[] | objects | {Key: .Key | split("/"), Value: .Value}' , but I just donβt understand how I can recursively rely on split (). Key and create nested objects. I think I will also need sort_by (.Key) to process the data out of order if I cannot | add | add arbitrarily and not allow jq structure.
I understand that xxxxx is base64 encoded, and hopefully base64d will be merged soon, but until then I think I can handle decoding with subsequent shell processing.
source share