JSON & YAML Wranglin'
jq, yq, flat, etc.
Warning: This section is under construction
Install all three with nix
nix-shell -p nodePackages.npm jq yq-go
# process file contents
cat ./wiki/sidebar.yml | yq -o json | npx flat
# process multiline input
cat <<EOF | yq -o json | npx flat
- name: Cloud
href: /wiki/cloud/overview
posts:
- name: Amazon Web Services (AWS)
href: /wiki/cloud/aws/overview
posts:
- name: CloudWatch
href: /wiki/cloud/aws/cloudwatch
- name: S3
href: /wiki/cloud/aws/s3
EOF
Output:
{
"0.name": "Cloud",
"0.href": "/wiki/cloud/overview",
"0.posts.0.name": "Amazon Web Services (AWS)",
"0.posts.0.href": "/wiki/cloud/aws/overview",
"0.posts.0.posts.0.name": "CloudWatch",
"0.posts.0.posts.0.href": "/wiki/cloud/aws/cloudwatch",
"0.posts.0.posts.1.name": "S3",
"0.posts.0.posts.1.href": "/wiki/cloud/aws/s3"
}
Find all hrefs
jq -r 'to_entries | map(select(.key | match("(path|href)$";"i"))) | map(.value)'
cat <<EOF | yq -o json | npx flat | jq -r 'to_entries | map(select(.key | match("(href)$";"i"))) | map(.value)'
- name: Cloud
href: /wiki/cloud/overview
posts:
- name: Amazon Web Services (AWS)
href: /wiki/cloud/aws/overview
posts:
- name: CloudWatch
href: /wiki/cloud/aws/cloudwatch
- name: S3
href: /wiki/cloud/aws/s3
EOF
Output
[
"/wiki/cloud/overview",
"/wiki/cloud/aws/overview",
"/wiki/cloud/aws/cloudwatch",
"/wiki/cloud/aws/s3"
]
aws cloudfront list-distributions | jq ".DistributionList.Items | last"
Incase you don’t know the keys that are available and your output gets
truncated by your terminal, you can use keys
to debug.
aws cloudfront list-distributions | jq "keys"
aws cloudfront list-distributions | jq ".DistributionList | keys"
# etc.