Skip to content

Instantly share code, notes, and snippets.

@wwalker
Last active May 23, 2021 00:28
Show Gist options
  • Save wwalker/5739a1fccf162ce6e4e345fd945a09d9 to your computer and use it in GitHub Desktop.
Save wwalker/5739a1fccf162ce6e4e345fd945a09d9 to your computer and use it in GitHub Desktop.
jq and bookmarks
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"
}
]
}
```
{
"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"
}
]
}
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