Linux command
dasel 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Query a value
dasel -f [file.json] '[selector]'
Query a nested value
dasel -f [config.yaml] '.database.host'
Convert JSON to YAML
dasel -f [input.json] -p json -w yaml
Modify a value
dasel put -f [file.json] -v '[new_value]' '[selector]'
Delete a key
dasel delete -f [file.yaml] '[selector]'
Read from stdin
cat [file.yaml] | dasel -p yaml -w json
Query a value from XML
dasel -f [file.xml] '.root.element'
说明
dasel (Data Selector) is a command-line tool for querying and modifying structured data files. It provides a unified interface for working with JSON, YAML, TOML, XML, CSV, INI, and HCL formats using a consistent selector syntax. The tool supports three main operations: select for querying data, put for modifying or adding values, and delete for removing keys. Selectors use dot notation for nested access (e.g., `.database.host`) and bracket notation for array indices (e.g., `.users.0.name`). Dasel can convert between formats by specifying different input and output parsers, making it useful for configuration file transformations. It reads from files or stdin and writes to files or stdout, integrating well with shell pipelines.
参数
- -f, --file _PATH_
- Input file path; reads from stdin if omitted
- -p, --parser _FORMAT_
- Parser for input data (json, yaml, toml, xml, csv, ini, hcl); auto-detected from file extension
- -w, --write _FORMAT_
- Output format; defaults to input parser type
- -t, --type _TYPE_
- Value type for put command (string, int, bool, json)
- -v, --value _VALUE_
- Value to set with put command
- -o, --out _FILE_
- Output file path; writes to stdout if omitted
- -r, --read _FORMAT_
- Alias for --parser
- --pretty
- Pretty-print output for readability
- -n, --null
- Output null values explicitly
- --colour, --color
- Enable colored output
- --escape-html
- Escape HTML entities in output
- -h, --help
- Display help information
- -v, --version
- Display version information
FAQ
What is the dasel command used for?
dasel (Data Selector) is a command-line tool for querying and modifying structured data files. It provides a unified interface for working with JSON, YAML, TOML, XML, CSV, INI, and HCL formats using a consistent selector syntax. The tool supports three main operations: select for querying data, put for modifying or adding values, and delete for removing keys. Selectors use dot notation for nested access (e.g., `.database.host`) and bracket notation for array indices (e.g., `.users.0.name`). Dasel can convert between formats by specifying different input and output parsers, making it useful for configuration file transformations. It reads from files or stdin and writes to files or stdout, integrating well with shell pipelines.
How do I run a basic dasel example?
Run `dasel -f [file.json] '[selector]'` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -f, --file _PATH_ do in dasel?
Input file path; reads from stdin if omitted