#
Application JSONB Filtering
Application JSONB filtering supports either the dot notation:
$.container.list[0].element
or the bracket–notation:
$['container']['list'][0]['element']
#
Jsonb-filter expression
Every filter operation is sent using a POST request. Additionally, a new Content-Type header has been made for application JSONB Filtering. An example can be seen below:
curl --location --request POST 'http://localhost:8181/rests/data/network-topology:network-topology/topology=uniconfig/node=SampleNodeName/frinx-uniconfig-topology:configuration' \
--header 'Content-Type: application/filter-data+json' \
--data-raw '{
"query": "$.frinx-uniconfig-topology:configuration"
}'
The filter is located in the body of the request, not in the URI. Since it is located in the body, there is no need to escape characters. The body structure looks like this:
{
"query": "$['container']['list'][0]"
}
If the user wants to filter the list elements based on name, the query filter would look like this:
{
"query": "$['container']['list'][?(@.name == 'foo')]"
}
By default, the filter returns the same output structure as when calling a GET request. There is an option to add the whole parent structure, where the body will look like this:
{
"query": "$['container']['list'][?(@.name == 'foo')]",
"addParentStructure": true
}
This will filter out all the elements in the list whose name is foo.
#
Operators
Operators mentioned in the table below are used to construct a path.
#
Functions
Functions can be called at the end of the query path. The input to the function is the output of the path expression. The function output is dictated by the function itself.
#
Filter Operators
Filters are logical expressions used to filter arrays. A typical filter would be [?(@.age > 18)] where @ represents the current element being processed. More complex filters can be created with logical operators && and ||. String literals must be enclosed by:
- A single quote: [?(@.name == 'foo')]
- A double quote: [?(@.name == "foo")]
#
Jsonb-filter examples
Suppose we have the following data, and we want to do some filtering on them.
{
"ietf-interfaces:interfaces": {
"interface": [
{
"name": "eth0",
"type": "ethernetCsmacd",
"enabled": true,
"speed": 10
},
{
"name": "eth1",
"type": "ethernetCsmacd",
"enabled": true,
"speed": 20
},
{
"name": "eth1.10",
"type": "l2vlan",
"speed": 5
},
{
"name": "lo1",
"type": "softwareLoopback",
"speed": 10
}
],
"action": {
"name": "test-name",
"type": "test-type"
}
},
"fast": 10
}