Created
May 4, 2020 10:18
-
-
Save iinm/b0c47c44e2604fb9333c699a1b2ebb14 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set -eu -o pipefail | |
# given: | |
input=$(cat << JSON | |
{ | |
"a": 1, | |
"b": { "c": 2 }, | |
"d": { "e": [3, 4] } | |
} | |
JSON | |
) | |
# when: | |
out=$( | |
echo "$input" \ | |
| jq --raw-output 'leaf_paths as $path | "\($path | join(".")):\(getpath($path))"' \ | |
| sort \ | |
| paste --serial --delimiters "\t" | |
) | |
# then: | |
test "$out" = "$(echo -e "a:1\tb.c:2\td.e.0:3\td.e.1:4")" |
Author
iinm
commented
Feb 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment