quick scribles to remember jq usage
- identity
cat <file> | jq '.' - property access
cat <file> | jq '<name of property>' - combine two filters with |
cat <file> | jq '. | .foo' - provide 2 outputs with “,”
cat <file> | jq '. , .foo' - when mapping, “.” is considered each value, use map for array mapValues for objects
example
#! /usr/bin/env sh
cat ./storage.json | jq '.' | jq '.favorites' \
| jq 'map({"id": ., "with20delay": false, "with30delay": false})' | jq '{favorites: .}'Map a value with point-free style
#! /usr/bin/env sh
cat ./storage.json | jq '.favorites' | jq 'map(.rate |= tonumber)'