Last active
May 23, 2021 00:28
-
-
Save wwalker/5739a1fccf162ce6e4e345fd945a09d9 to your computer and use it in GitHub Desktop.
jq and bookmarks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This should work, but doesn't: | |
``` | |
@ $ jq '.. |= .title? as $title | .children |= map(. + {"parent": $title})' e.json | |
jq: error (at e.json:26): Cannot iterate over null (null) | |
``` | |
This works (almost) | |
``` | |
@ $ jq '. |= .title? as $title | .children |= map(. + {"parent": $title})' e.json | |
{ | |
"title": "Bookmarks bar", | |
"children": [ | |
{ | |
"title": "0 indexed", | |
"children": [ | |
{ | |
"title": "bookmark the first", | |
"uri": "https://bookmark.the.first.com/in-0-indexed" | |
}, | |
{ | |
"title": "second bookmark", | |
"uri": "https://second.bookmark.com/in-0-indexed" | |
} | |
], | |
"parent": "Bookmarks bar" | |
}, | |
{ | |
"title": "third bookmark", | |
"uri": "https://third.bookmark.com/not-nested", | |
"parent": "Bookmarks bar" | |
}, | |
{ | |
"title": "fourth bookmark", | |
"uri": "https://fourth.bookmark.com/not-nested", | |
"parent": "Bookmarks bar" | |
} | |
] | |
} | |
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"title": "Bookmarks bar", | |
"children": [ | |
{ | |
"title": "0 indexed", | |
"children": [ | |
{ | |
"title": "bookmark the first", | |
"uri": "https://bookmark.the.first.com/in-0-indexed" | |
} | |
] | |
}, | |
{ | |
"title": "second bookmark", | |
"uri": "https://second.bookmark.com/not-nested" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
something like: | |
Bookmarks bar: | |
Bookmarks bar.0 indexed: | |
Bookmarks bar.0 indexed.Bookmarks bar.0 indexed: https://bookmark.the.first.com/in-0-indexed | |
Bookmarks bar.0 indexed.second bookmark: https://second.bookmark.com/not-nested |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment