dasel
"Select, put and delete data from JSON, TOML, YAML, XML and CSV files with a single tool. Supports conversion between formats and can be used as a Go package." - https://github.com/TomWright/dasel
Example usage
Convert between formats
yaml to toml
dasel --read yaml --write toml --file vector.yaml > vector.toml
json to yaml with a data filter
dasel -r json -w yaml -f ansible-facts.json '.ansible_facts.ansible_default_ipv4'
Restructure a pagerduty csv
Download the csv using this shell function that uses BSD (macOS) date
and open
:
pagerduty-csv-download() {
TZ=America/Los_Angeles
past="$(date -v-7d "+%FT%T")"
present="$(date "+%FT%T")"
open "$(date "+https://company-name.pagerduty.com/api/v1/reports/raw/incidents.csv?since=${past}&until=${present}&time_zone=${TZ}")"
}
Then restructure it using --format
to interpolate variables into a template string:
dasel -f incidents.csv -w json -m --format '{{ .created_on }} https://company-name.pagerduty.com/incidents/{{ .id }} {{ .description }}' '.[*]'
The output will be something like:
2022-02-02T20:02:02-08:00 https://company-name.pagerduty.com/incidents/Q0ZL9NU2 [FIRING:1] TargetDown (cat-downloader)
Pretty format a gpx file
This is useful for comparing two files, for instance where one may have been appended, and you need to make sure.
dasel -r xml -f 2022-01-02-18-20-00.gpx > old.gpx
Keep in mind though that pretty-formatted gpx files take up significantly more space.
Compact format a gpx file
dasel
supports compact formatting, which can save disk space by eliminating whitespace characters. In dasel
1.x this is -c
, but in 2.x it is --pretty=false
.
dasel -r xml -f books.xml --pretty=false
My tests show this compact output saving ~25% in gpx files compared to a formatted gpx file using whitespace, and 15% compared to a gpx file using tabs.