content mapping in jq :: the filter maps each post to its slug, and the reverse filter reverts it
Last active
March 13, 2020 17:47
-
-
Save sonnyksimon/3c01f5a4a6da047a045acdf6dabf1c40 to your computer and use it in GitHub Desktop.
content mapping in jq :: the filter maps each post to its slug, and the reverse filter reverts it
This file contains 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
{ | |
"content": [ | |
{ | |
"title": "first post", | |
"slug": "one", | |
"body": "The quick brown fox jumps over the lazy dog.", | |
"author": "anon", | |
"updated": "NaN" | |
}, | |
{ | |
"title": "another one", | |
"slug": "two", | |
"body": "The second brown fox jumps over the lazy dog.", | |
"author": "anon", | |
"updated": "NaN" | |
} | |
] | |
} |
This file contains 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
reduce .content[] as {$title, $slug, $body, $author, $updated} ({}; (.[$slug] += {$title, $body, $author, $updated})) |
This file contains 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
to_entries | map(.value += {slug:.key}) | {content:[.[].value]} |
This file contains 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
{ | |
"one": { | |
"title": "first post", | |
"body": "The quick brown fox jumps over the lazy dog.", | |
"author": "anon", | |
"updated": "NaN" | |
}, | |
"two": { | |
"title": "another one", | |
"body": "The second brown fox jumps over the lazy dog.", | |
"author": "anon", | |
"updated": "NaN" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment