Appendix: Using the DATAFILTER Element Tag
The DATAFILTER element retrieves a sub-set of JSON data from a local variable and assigns the result to another variable. If no matching results are found, the result will consist of an empty set of braces.
Implementation:
- Click to open the Element Browser to the right of the window.
- Use the Filter menu to select Tags.
- Locate and select DATAFILTER.
The element has the following syntax:
<%# DATAFILTER(
Keyword
Path
NewKeyword) %>
Parameters can be entered in any order.
All parameters are required:
Parameter | Description |
---|---|
Keyword | The keyword associated with the intended local data. |
Path | The path of the intended data. |
NewKeyword | The keyword of the intended destination variable. |
The following example demonstrates how to query JSON assigned to the AllBooks variable, retrieve data about books whose price is less than 10, and assign the result to the BooksPricedLessThan10 variable.
<%# DATAFILTER(
Keyword="AllBooks"
Path="$..book[?(@.price<10)]"
NewKeyword="BooksPricedLessThan10") %>
An example of the data returned by the element is shown below:
{ "result":[ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 } ] }
The following example changes the Path parameter so the element returns only books that have an ISBN number, and assigns the result to BooksWithISBN:
<%# DATAFILTER(
Keyword="AllBooks"
Path="$..book[?(@.isbn)]"
NewKeyword="BooksWithISBN") %>
This time, the results will look something like this:
{ "result":[ { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ] }