jsonyx.select_nodes¶
- jsonyx.select_nodes(nodes, query, *, allow=NOTHING, allow_slice=False, relative=False, use_decimal=False)[source]¶
Select nodes from a node or a list of nodes.
Added in version 2.0.
- Parameters:
nodes (_Node |
list[_Node]) – a node or a list of nodesquery (
str) – an JSON select queryallow (
Container[str], default:NOTHING) – the JSON deviations fromjsonyx.allowallow_slice (
bool, default:False) – allow slicerelative (
bool, default:False) – query must start with"@"instead of"$"use_decimal (
bool, default:False) – usedecimal.Decimalinstead offloat
- Raises:
IndexError – if an index is out of range
JSONSyntaxError – if the select query is invalid
KeyError – if a key is not found
TypeError – if a value has the wrong type
- Returns:
list[_Node] – the selected list of nodes
- Example:
>>> import jsonyx as json >>> obj = [1, 2, 3, 4, 5, 6] >>> root = [obj] >>> node = root, 0 # pointer to obj >>> for target, key in json.select_nodes(node, "$[@ > 3]"): ... target[key] = None ... >>> root[0] [1, 2, 3, None, None, None]