Whenever an attribute has the attribute type Object
, it is a JSON Object. As JSON Objects behave differently than Arrays there are corresponding filters.
Field type: JSON
Filters: contains
, contained_by
, has_key
, has_any_keys
, has_keys
, isnull
contains
The filters contains
and contained_by
are explained in the Array section. The same logic applies but on the whole object. Please note that this query is case sensitive.
GET https://industrial.api.ubidots.com/api/v2.0/devices/?properties__contains={"country":"Colombia"}
//Returns Array 'results' with device containing the property 'Colombia'
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"properties": {
"city": "Medellín",
"country": "Colombia",
},
...
}
]
}
contained_by
Filters for the JSON objects that are completely contained by the object provided in the query.
GET https://industrial.api.ubidots.com/api/v2.0/devices/?properties__contained_by={"_isDemo": true}
//Returns Array 'results' with matching JSON Objects (and empty JSON objects)
{
"count": 3,
"next": null,
"previous": null,
"results": [
{
"properties": {
"_isDemo": true
},
...
},
{
"properties": {},
...
},
{
"properties": {},
...
}
]
}
Attention
Empty Objects are contained by any superset provided, hence all empty JSON Objects are retrieved as well. To avoid that, please use additionally the
has_key
orhas_keys
with the corresponding keys desired.
has_key / has_keys /has_any_keys
Filters for JSON Objects that have the provided key(s).
has_key
filters for a single key.
has_keys
filters for a list of keys. A JSON Object has to have all keys to match (AND)
has_any_key
filters for a list of keys like an overlap. A JSON Object has to match only one key (OR).
//has_key
GET https://industrial.api.ubidots.com/api/v2.0/devices/?properties__has_key="_isDemo"
//Returns Array 'results' with JSON Object containing key '_isDemo'
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"properties": {
"_isDemo": true
},
...
}
]
}
//has_keys
GET https://industrial.api.ubidots.com/api/v2.0/devices/?properties__has_keys=["country", "city"]
//Returns Array 'results' with JSON Objects containing the keys provided
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"properties": {
"city": "Medellín", }
},
"country": "Colombia",
},
...
},
{
"properties": {
"city": "New York",
"country": "United States"
},
...
}
]
}
//has_any_keys
GET https://industrial.api.ubidots.com/api/v2.0/devices/?properties__has_any_keys=["country","continent"]
//Returns Array 'results' with all JSON Objects matching at least one key
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"properties": {
"city": "Medellín",
"continent": "South America",
},
...
},
{
"properties": {
"city": "New York",
"country": "United States"
},
...
}
]
}
The __isnull
filter can be applied to JSON Objects as described in the Boolean section.