LinuxCommandLibrary

dasel

Select, update, and convert data structures

SYNOPSIS

dasel <selector> [options] [<file>]
dasel <subcommand> <selector> [options] [<file>]

Common subcommands:
dasel select <selector> [options] [<file>]
dasel put <selector> [options] [<file>]
dasel delete <selector> [options] [<file>]
dasel convert [options] [<file>]

PARAMETERS

-f, --file <path>
    Specifies the input file path. If omitted, dasel reads from standard input (stdin).

-p, --parser <format>
    Defines the parser to use for the input data (e.g., json, yaml, toml, xml, csv, properties). Auto-detected by file extension if possible.

-t, --type <format>
    Defines the output format (e.g., json, yaml, toml, xml, csv, properties). Defaults to the input parser type.

-s, --selector <expression>
    The selector expression used to target specific data elements. Often provided as a positional argument.

-w, --write
    Writes changes back to the input file. Requires --file to be specified.

-v, --value <value>
    The value to set when using the put subcommand.

-a, --append
    Used with put to append a value to an array at the selected path.

--pretty
    Pretty-prints the output JSON or YAML data for readability.

--version
    Displays the dasel version information.

--help
    Shows the help message for the command or subcommand.

DESCRIPTION

Dasel is a powerful command-line tool designed for querying and modifying data structures, serving as a universal alternative to specialized tools like jq for JSON or yq for YAML. It supports a wide array of data formats including JSON, YAML, TOML, XML, CSV, and Properties files, allowing users to interact with structured data using a unified selector syntax.

The tool excels in scenarios requiring automation, scripting, or quick data manipulation without the need for complex programming. Users can select specific values, update existing data, delete entries, or even convert data between different formats. Its intuitive selector language, reminiscent of CSS selectors or object pathing, makes it accessible for navigating nested data. Dasel streamlines data processing tasks, making it an indispensable utility for developers and system administrators working with diverse configuration files and data payloads.

CAVEATS

While powerful, dasel's universal nature means its selector syntax can be less specialized than format-specific tools (e.g., jq's extensive function library). Mastering its selector syntax requires a learning curve, especially for complex queries or transformations. Performance on extremely large datasets might not match highly optimized, native format parsers.

SUPPORTED DATA FORMATS

Dasel natively supports a wide range of structured data formats for both input and output:

  • JSON (JavaScript Object Notation)
  • YAML (YAML Ain't Markup Language)
  • TOML (Tom's Obvious, Minimal Language)
  • XML (eXtensible Markup Language)
  • CSV (Comma Separated Values)
  • Properties (Java Properties files)

SELECTOR SYNTAX OVERVIEW

Dasel employs a flexible selector syntax to pinpoint data elements. Key components include:

  • Dot Notation: Access object fields (e.g., user.profile.name)
  • Array Indexing: Access array elements (e.g., items[0], items[:] for all)
  • Filters: Select elements based on conditions (e.g., users[name=John])
  • Wildcards: Match any key or index (e.g., *.id)
  • Root Selector: . refers to the root of the document.
This allows for powerful and precise data navigation.

HISTORY

Dasel was created by Tom Wright (also known as TomKennedy on GitHub) and first released in 2020. Developed in Go, it was designed to address the need for a single, versatile command-line tool capable of processing various structured data formats, drawing inspiration from the success of jq for JSON data. Its open-source development and active community have contributed to its growing popularity as a go-to utility for data manipulation on the command line.

SEE ALSO

jq(1), yq(1), xmllint(1), grep(1), awk(1), sed(1)

Copied to clipboard