Dasel Documentation

repository·master·Indexed 27 days ago

https://github.com/tomwright/dasel

Dasel (Data-Select) is a command-line tool and library for querying, modifying, and transforming data across multiple formats, including JSON, YAML, TOML, XML, CSV, HCL, INI, and KDL, using a unified syntax. It provides a CLI for data extraction and conversion, as well as a Go library featuring the execution and model packages for programmatic data manipulation via Select(), Query(), and Modify() functions.

Tokens
1.8K
Snippets
5
Records
23
Agent score
93%

What's inside Dasel

  1. Execute selectors on model values using the execution package

    master
    The execution package allows you to perform data extraction by taking a model.Value, parsing a selector string into an Abstract Syntax Tree (AST), and then executing that AST against the provided value.
  2. Install Dasel

    master

    You can install Dasel using Homebrew, Go, or by downloading prebuilt binaries.

    Homebrew (macOS/Linux)

    brew install dasel

    Go Install

    go install github.com/tomwright/dasel/v3/cmd/dasel@master

    Prebuilt Binaries

    Prebuilt binaries for Linux, macOS, and Windows are available on the GitHub Releases page.

    brew install dasel
  3. Configure shell completion for Dasel

    master

    Dasel supports tab-completion for Bash, Zsh, Fish, and PowerShell. Use the following commands to generate and load the completion scripts for your current session.

    # Bash
    source <(dasel completion bash)
    
    # Zsh
    source <(dasel completion zsh)
    
    # Fish
    dasel completion fish | source
    
    # PowerShell
    dasel completion powershell | Out-String | Invoke-Expression
  4. Modify values in place

    master

    You can update, insert, or delete values using the assignment syntax within a selector.

    To output only the modified value, use the standard selection syntax. To output the entire document after modification, include the --root flag.

  5. Use recursive descent and search selectors

    master

    Dasel provides advanced selectors for traversing and finding data:

    • Recursive Descent (..): Searches all nested objects and arrays for a matching key or index.
    • Search (search): Finds all values matching a specific condition anywhere in the structure.

    Examples

    # Recursive descent to find all 'bar' keys
    echo '{"foo": {"bar": "baz"}}' | dasel -i json '..bar'
    
    # Search for values where 'bar' equals 'baz'
    echo '{"foo": {"bar": "baz"}}' | dasel -i json 'search(bar == "baz")'
  6. Select values from data structures

    master

    By default, Dasel evaluates the provided selector and prints the result. Use the -i flag followed by the input format (e.g., json) and the selector string.

    echo '{"foo": {"bar": "baz"}}' | dasel -i json 'foo.bar'
    # Output: "baz"
  7. Query data using Query()

    master
    Use Query to execute a selector against a data structure and receive the results as a slice of *model.Value pointers. This is useful when you need to inspect the metadata or specific types of the selected values using the model package.
  8. Select data as native Go types using Select()

    master
    Use Select to execute a selector and get the results converted into native Go types (e.g., string, int, map[string]any, []any). The function returns a slice of any containing the results and the count of items found. Note that ordering within maps is not guaranteed.