search
The search function performs a predicate-based recursive search of the document tree.
It allows you to find nodes that match specific conditions, not just by key name.
This makes search a more flexible and powerful alternative to the .. operator, which is shorthand for simple recursive key or index lookups.
Syntax
search(PREDICATE)Where PREDICATE is a function that tests each node and returns true/false.
Behaviour
Traverses the entire document tree, starting at the current node.
Applies the given predicate to every node (objects, arrays, scalars).
Returns all nodes that satisfy the predicate.
Unlike
..,searchis not limited to key names or indices — it supports arbitrary conditions.
Predicates
Commonly used predicate functions include:
has("KEY")— true if the node has the given key.$this == VALUE— true if the node equalsVALUE.
📌 Check the functions documentation for a full list.
Examples
Example Input
{
"users": [
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
],
"meta": {
"active": true,
"score": 42
}
}1. Search for Nodes with a Key
Find all nodes that contain a name field:
dasel -f data.json 'search(has("name"))'Output:
{ "id": 1, "name": "Alice" }
{ "id": 2, "name": "Bob" }2. Search for Specific Values
Find all nodes where the value equals 42:
dasel -f data.json 'search($this == 42)'Output:
423. Combining Predicates
Find all nodes that have both id and name keys:
dasel -f data.json 'search(has("id") && has("name"))'Output:
{ "id": 1, "name": "Alice" }
{ "id": 2, "name": "Bob" }Comparison to ..
....is shorthand for recursive key/index lookups:..name≈search(has("name"))..[0]≈search(has(0))
searchallows arbitrary logic, making it more powerful but also more verbose.
Notes
searchis ideal when you need fine-grained control over what you’re looking for.Use the recursive descent operator (
..) for simple lookups by key or index.Both operators traverse the document tree recursively — the difference is specificity vs flexibility.
Last updated