Query syntax
Overview
Dasel queries are composed of one or more statements. Each statement describes how to navigate or transform the data, and the final statement determines the output value.
A statement is made up of a sequence of accessors or function calls, chained together with a dot (.) and terminated with a semi-colon (;).
Accessors let you step into nested structures (e.g. objects, arrays, maps).
Functions apply transformations or filters to the current value.
Example
Suppose you have the following JSON document:
{
"users": [
{
"id": 1,
"name": "Alice",
"active": true
},
{
"id": 2,
"name": "Bob",
"active": false
}
]
}A dasel query might look like this:
$activeUsers = $root.users.filter(active == true);
$activeUsers.map(name)$activeUsers =Variable assignment.$rootAccess the root document.usersAccess theusersfield.filter(active == true)Filter theuserslist to only include elements whereactiveistrue.;Terminate the statement.$activeUsersAccess the active users variable we just created.mapIterate through each active user, returning the specified value, in this casename. (Since this is the last statement, this is also the output value.)
Output:
[
"Alice"
]This query could be written in a more compact form, or split into multiple statements for clarity. The following examples are equivalent and will all produce the same result:
$root.users.filter(active == true).map(name)$activeUsers = $root.users.filter(active == true);
$activeUsers.map(name)$activeUsers = $root.users.filter(active == true);
$names = $activeUsers.map(name);
$namesLast updated