githubEdit

Recipes

Practical recipes for common tasks with dasel.


Convert between formats

JSON to YAML

$ echo '{"name": "Tom", "age": 30}' | dasel -i json -o yaml
name: Tom
age: 30

YAML to JSON

$ echo 'name: Tom
age: 30' | dasel -i yaml -o json
{
    "name": "Tom",
    "age": 30
}

Extract a nested value

$ echo '{"server": {"host": "localhost", "port": 8080}}' \
  | dasel -i json 'server.port'
8080

Filter an array of objects

Get names of active users:


Count matching items

Count how many items have a specific status:


Rename a key

Use entries, map, and fromEntries to transform map keys:


Sum values from an array of objects


Provide a default for a missing field

Use the ?? coalesce operator:


Merge two objects


Sort and deduplicate an array


Conditionally transform values

Classify scores into grades:


Search deeply nested data

Find all objects with a name field anywhere in the document:


Build a new object from existing data

Last updated