Convert Figma logo to code with AI

TomWright logodasel

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.

7,116
135
7,116
38

Top Related Projects

13,829

Make JSON greppable!

2,601

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents

30,342

Command-line JSON processor

3,279

Pure Go implementation of jq

18,987

Terminal JSON viewer & processor

Quick Overview

Dasel (Data Selector) is a command-line tool and Go library for querying and modifying data structures. It supports various data formats including JSON, YAML, TOML, and XML, allowing users to easily extract, modify, and transform data across these formats.

Pros

  • Multi-format support: Works with JSON, YAML, TOML, and XML
  • Powerful query language: Supports complex data selections and modifications
  • Format conversion: Can convert data between supported formats
  • Lightweight and fast: Efficient for both small and large datasets

Cons

  • Learning curve: Requires understanding of the query syntax
  • Limited to supported formats: May not work with less common data formats
  • Command-line focus: Might be less intuitive for users preferring GUI tools
  • Documentation could be more extensive: Some advanced features may require experimentation

Code Examples

  1. Selecting a value from JSON:
value, err := dasel.New(jsonData).Select(".users.[0].name")
if err != nil {
    log.Fatal(err)
}
fmt.Println(value)
  1. Modifying a YAML file:
err := dasel.New(yamlData).Put(".config.timeout", "30s")
if err != nil {
    log.Fatal(err)
}
  1. Converting TOML to JSON:
jsonData, err := dasel.New(tomlData).ToJSON()
if err != nil {
    log.Fatal(err)
}
fmt.Println(string(jsonData))

Getting Started

To use Dasel as a Go library, first install it:

go get github.com/tomwright/dasel

Then, import it in your Go code:

import "github.com/tomwright/dasel"

func main() {
    data := []byte(`{"name": "John", "age": 30}`)
    value, err := dasel.New(data).Select(".name")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(value)
}

This example demonstrates how to select a value from a JSON string using Dasel.

Competitor Comparisons

13,829

Make JSON greppable!

Pros of gron

  • Simpler, more focused tool specifically for flattening JSON
  • Easier to learn and use for basic JSON manipulation tasks
  • Outputs in a grep-friendly format, making it ideal for command-line piping

Cons of gron

  • Limited to JSON input and output formats
  • Lacks advanced querying and modification capabilities
  • Not designed for handling other data formats like YAML or TOML

Code Comparison

gron:

gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page=1" | grep "commit.author"

dasel:

dasel -r json -w plain ".[0].commit.author" < <(curl -s "https://api.github.com/repos/TomWright/dasel/commits?per_page=1")

Summary

gron is a specialized tool for flattening JSON, making it easy to grep and manipulate JSON data in the command line. It's simpler to use for basic tasks but limited to JSON.

dasel is a more versatile tool that supports multiple data formats and offers advanced querying and modification capabilities. It's more powerful but may have a steeper learning curve for simple tasks.

Choose gron for quick JSON flattening and grepping, or dasel for a more comprehensive data manipulation tool across various formats.

2,601

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents

Pros of yq

  • Built on top of jq, leveraging its powerful JSON processing capabilities
  • Supports YAML, XML, and TOML in addition to JSON
  • Extensive documentation and examples available

Cons of yq

  • Requires Python runtime, which may add overhead
  • Less focused on being a standalone CLI tool compared to Dasel
  • May have a steeper learning curve due to jq syntax

Code Comparison

yq:

yq '.users[] | select(.age > 30) | .name' input.yaml

Dasel:

dasel select -f input.yaml '.users.(age>30).name'

Both tools allow for querying and manipulating structured data, but they use different syntaxes. yq leverages jq-style expressions, while Dasel uses a more straightforward dot notation with built-in functions.

yq excels in environments where Python is already available and when working with multiple data formats. It's particularly powerful for complex data transformations due to its jq foundation.

Dasel, on the other hand, is designed as a standalone CLI tool with a focus on simplicity and ease of use. It's a good choice for users who prefer a more intuitive syntax and don't require the full power of jq-style expressions.

The choice between yq and Dasel depends on the specific use case, existing environment, and personal preference for syntax and features.

30,342

Command-line JSON processor

Pros of jq

  • More mature and widely adopted project with extensive documentation
  • Powerful and expressive query language specifically designed for JSON manipulation
  • Faster performance for large JSON datasets

Cons of jq

  • Limited to JSON format only
  • Steeper learning curve due to its unique query syntax
  • Less versatile for handling multiple data formats in a single command

Code Comparison

jq example:

echo '{"name": "John", "age": 30}' | jq '.name'

dasel example:

echo '{"name": "John", "age": 30}' | dasel -r json '.name'

Key Differences

  • dasel supports multiple data formats (JSON, YAML, TOML, XML), while jq is JSON-specific
  • jq has a more powerful query language for complex JSON transformations
  • dasel offers a more intuitive syntax for basic operations across various formats
  • jq is generally faster for large JSON datasets, but dasel provides broader format support

Use Cases

jq is ideal for:

  • Complex JSON data manipulation and analysis
  • High-performance JSON processing in data pipelines

dasel is better suited for:

  • Working with multiple data formats in a single tool
  • Simpler queries across various structured data formats
  • Quick data extraction tasks with minimal syntax learning
3,279

Pure Go implementation of jq

Pros of gojq

  • Faster performance for JSON processing
  • More extensive JSON query language support
  • Closer compatibility with jq, making it easier for users familiar with jq

Cons of gojq

  • Limited to JSON format, while Dasel supports multiple data formats
  • Less versatile for general data manipulation tasks
  • Steeper learning curve for those not familiar with jq syntax

Code Comparison

gojq:

input := `{"name": "John", "age": 30}`
query := ".name"
output, _ := gojq.Run(input, query)
fmt.Println(output) // Output: "John"

Dasel:

input := `{"name": "John", "age": 30}`
sel, _ := dasel.New(input)
output, _ := sel.Query(".name")
fmt.Println(output) // Output: "John"

Both gojq and Dasel are powerful tools for data manipulation, but they serve different purposes. gojq excels in JSON processing with its extensive query language and performance optimizations. It's an excellent choice for users familiar with jq or those working primarily with JSON data.

Dasel, on the other hand, offers broader format support and a more intuitive syntax for general data manipulation tasks. It's more versatile and easier to pick up for users without prior jq experience.

The choice between gojq and Dasel depends on the specific use case, data formats involved, and the user's familiarity with jq-like query languages.

18,987

Terminal JSON viewer & processor

Pros of fx

  • Specialized for JSON manipulation with a more interactive, terminal-based interface
  • Supports JavaScript expressions for advanced data transformations
  • Offers a live preview feature for real-time data exploration

Cons of fx

  • Limited to JSON format, while Dasel supports multiple data formats
  • Lacks the ability to modify files in-place, which Dasel provides
  • May have a steeper learning curve for users unfamiliar with JavaScript

Code Comparison

fx example:

echo '{"key": "value"}' | fx 'x => x.key'

Dasel example:

echo '{"key": "value"}' | dasel -r json '.key'

Summary

fx excels in JSON manipulation with its interactive interface and JavaScript-based transformations. However, Dasel offers broader format support and in-place file modifications. fx is ideal for JSON-centric workflows, while Dasel provides more versatility across different data formats.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

dasel

Gitbook Go Report Card PkgGoDev Test Build codecov Mentioned in Awesome Go GitHub All Releases Downloads GitHub License GitHub tag (latest by date) Homebrew tag (latest by date)

Dasel (short for data-selector) allows you to query and modify data structures using selector strings.

Comparable to jq / yq, but supports JSON, YAML, TOML, XML and CSV with zero runtime dependencies.

One tool to rule them all

Say good bye to learning new tools just to work with a different data format.

Dasel uses a standard selector syntax no matter the data format. This means that once you learn how to use dasel you immediately have the ability to query/modify any of the supported data types without any additional tools or effort.

Update Kubernetes Manifest

Commands executed in the demo
# Piping data into dasel
echo '{"demo": "Integrating with github releases..."}' | dasel -r json 'demo'

# Fetch dasel releases from github api
curl -L \
    -H "Accept: application/vnd.github+json" \
    -H "X-GitHub-Api-Version: 2022-11-28" \
    https://api.github.com/repos/TomWright/dasel/releases > releases.json
less releases.json

# Extract and structure release data by version with download URL's by asset name
dasel -f releases.json -w yaml 'all().mapOf(version,tag_name,download,assets.all().mapOf(name,name,url,browser_download_url).merge()).merge()' > releases_download.yaml
less releases_download.yaml

# Restructure the above data into CSV format, destructuring into rows.
dasel -f releases_download.yaml -w csv 'all().download.all().mapOf(version,parent(2).version,name,name,url,url).merge()' > releases_download.csv
less releases_download.csv

# Fetch the first CSV row and output as JSON
dasel -f releases_download.csv -w json 'first()'

Table of contents

Quickstart

Dasel is available on homebrew, ASDF, scoop, docker, Nix or as compiled binaries from the latest release.

brew install dasel

You can also install a development version with:

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

For more information see the installation documentation.

Select

echo '{"name": "Tom"}' | dasel -r json 'name'
"Tom"

See select documentation.

Convert json to yaml

echo '{"name": "Tom"}' | dasel -r json -w yaml
name: Tom

See select documentation.

Put

echo '{"name": "Tom"}' | dasel put -r json -t string -v 'contact@tomwright.me' 'email'
{
  "email": "contact@tomwright.me",
  "name": "Tom"
}

See put documentation.

Delete

echo '{
  "email": "contact@tomwright.me",
  "name": "Tom"
}' | dasel delete -r json '.email'
{
  "name": "Tom"
}

See delete documentation.

Completion

If you want to use completion from the terminal you can do the following (using zsh in this example):

Add the following to ~/.zshrc and reload your terminal.

export fpath=(~/zsh/site-functions $fpath)
mkdir -p ~/zsh/site-functions
dasel completion zsh > ~/zsh/site-functions/_dasel
compinit

Pre-Commit

Add dasel hooks to .pre-commit-config.yaml file

- repo: https://github.com/TomWright/dasel
  rev: v1.25.1
  hooks:
    - id: dasel-validate

for a native execution of dasel, or use:

  • dasel-validate-docker pre-commit hook for executing dasel using the official Docker images
  • dasel-validate-bin pre-commit hook for executing dasel using the official binary

Issue vs Discussion

I have enabled discussions on this repository.

I am aware there may be some confusion when deciding where you should communicate when reporting issues, asking questions or raising feature requests so this section aims to help us align on that.

Please raise an issue if:

  • You find a bug.
  • You have a feature request and can clearly describe your request.

Please open a discussion if:

  • You have a question.
  • You're not sure how to achieve something with dasel.
  • You have an idea but don't quite know how you would like it to work.
  • You have achieved something cool with dasel and want to show it off.
  • Anything else!

Features

Documentation

The official dasel docs can be found at daseldocs.tomwright.me.

Playground

You can test out dasel commands using the playground.

Source code for the playground can be found at github.com/TomWright/daselplayground.

Benchmarks

In my tests dasel has been up to 3x faster than jq and 15x faster than yq.

See the benchmark directory.

Stargazers over time

Stargazers over time