Skip to main content

Selecting conditional data

You can use DronaHQ Query Language (DQL) to filter for specific data in your responses. Multiple responses return in an array. Single responses return as a single record. Sample data and DQL examples are below.

Contents​

Example JSON​

The examples below use this JSON data:

{
"customer info": {
"customer field": "Customer data",
"unformated_customer_field": " customer \n stuff ",
"total_value": "281.01",
"associated_usernames": ["user1, myuser, online_user"]
},
"payments": [
{
"invoice_number": "101301",
"date": "2022-09-11T16:12:34.494Z",
"description": "recurring subscription",
"amount": 110.48
},
{
"invoice_number": "101302",
"date": "2022-09-29T14:45:13.148Z",
"description": "one time purchase",
"amount": 24.49
},
{
"invoice_number": "101303",
"date": "2022-10-11T16:12:34.683Z",
"description": "recurring subscription",
"amount": 110.48
},
{
"invoice_number": "101304",
"date": "2022-10-12T11:45:22.182Z",
"description": "recurring subscription deluxe",
"amount": 35.56
}
]
}

Filter query results for objects with specific key-value pairs​

The example below filters for objects in the payments array that have the key-value pair "description": "recurring subscription".

DQL​
payments[description="recurring subscription"]
Result​
[
{
"invoice_number": "101301",
"date": "2022-09-11T16:12:34.494Z",
"description": "recurring subscription",
"amount": 110.48
},
{
"invoice_number": "101303",
"date": "2022-10-11T16:12:34.683Z",
"description": "recurring subscription",
"amount": 110.48
}
]

DQL uses the same syntax to navigate filtered query results as it does to navigate JSON data. The example below gets the values from the invoice.number fields in the payments array.

DQL​
payments[description="recurring subscription"].invoice_number
Result​
["101301","101303"]

Return a single record​

When a filter has a single result, it returns as a record instead of an array. The filter below returns a single result as a record.

DQL​
payments[description="recurring subscription deluxe"].invoice_number
Result​
["101304"]

Check if a field has a specific value​

DQL can check if your query results have a specific key-value pair and return true or false. The example below checks the first item in the payments array for the key-value pair "description": "recurring".

DQL​
$contains(payments[0].description, "recurring")
Result​
true

Get only unique payment amounts​

The $distinct function returns a single instance of any recurring values. In the example below, the 110.48 value appears twice in the data, but only once in the result.

DQL​
$distinct(payments.amount)
Result​
[110.48, 24.49, 35.56]