Select Json¶
Filter a Json structure, keeping entries that match a query.
Documentation¶
For more information about how to write Json queries, see Json query syntax.
If Match anywhere is not checked (the default) the query must
match starting at the root of the Json structure. E.g. the query
articles
only matches if the root entry is a dictionary containing the
key “articles”. Conversely, if Match anywhere is checked the
query articles
can matches the key “articles” in any dictionary in the
whole structure. It can even match at several places despite the query just
being a simple key.
If Only output matching is checked, only output the parts that actually match the query, discarding any containing lists or dictionaries. If the query is capable of matching multiple entries (i.e. if it includes slices or patterns or if “Match anywhere” is checked), all the matching entries are placed in a list.
Using predicates¶
A predicate is a function that takes a Json entry as its only argument and
returns a boolean. It can be entered either as a lambda expression or as a
function definition using def
., e.g:
lambda entry: entry['score'] >= 100
or:
def filter_by_score(entry):
return entry['score'] >= 100
When predicate is used each selected entry in the Json structure is passed
to the predicate function which can then return True for entries that
should be added to the output and False for those that should not.
If evaluating the predicate raises an exception this is treated the same as returning False.
Definition¶
Input ports¶
- input json
Input
Output ports¶
- output json
Output
Configuration¶
- Match anywhere (anywhere)
Match the query at any position in the Json structure.
- Only output matching (only_matching)
When checked, only output the parts that actually match the query, discaring any parent containers. If the query is capable of matching multiple entries (i.e. if it includes slices or patterns or if “Match anywhere” is checked), all the matching entries are placed in a list.
- Predicate (predicate)
The predicate can be entered as a python function (def or lambda) which takes an entry in the Json structure as its only argument and returns either True if that entry should be included, or False if it shouldn’t
- Query (query)
Query for selecting entries in the Json structure. The visual editor can help you create a query which selects a single entry. The query can then be edited manually to include slices (e.g. [2:4]) or patterns (e.g. some*key) which will select multiple entries. For more details see the node’s documentation.
- Filter by predicate (use_predicate)
When checked, each entry in the data selected by the query will be passed to the predicate function and will only be included in the output if the predicate function returns True.
Examples¶
Implementation¶
- class node_filterjson.SelectJson[source]