-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Let's take the recurse
example from the manual, and add a bunch of useless {"foo": "bar"}
to it:
{"name": "/", "foo": "bar", "children": [
{"name": "/bin", "foo": "bar", "children": [
{"name": "/bin/ls", "foo": "bar", "children": []},
{"name": "/bin/sh", "foo": "bar", "children": []}]},
{"name": "/home", "foo": "bar", "children": [
{"name": "/home/stephen", "foo": "bar", "children": [
{"name": "/home/stephen/jq", "foo": "bar", "children": []}]}]}]}
recurse(.children[]) | .name
will give me all the name
s, but destroy the structure of the JSON in the process.
Is there a way to get that information, but preserve the structure?
With the JSON above, this would be the output:
{"name": "/", "children": [
{"name": "/bin", "children": [
{"name": "/bin/ls", "children": []},
{"name": "/bin/sh", "children": []}]},
{"name": "/home", "children": [
{"name": "/home/stephen", "children": [
{"name": "/home/stephen/jq", "children": []}]}]}]}