json_path_multi
Extracts all matching values from a dictionary or list using a JSON path expression. Unlike json_path, which returns only the first match, this function returns a list of all matches.
Syntax
json_path_multi(path, obj)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| path | string | Yes | A JSON path expression specifying the locations to extract. |
| obj | dict or list | Yes | The dictionary or list to search. |
Returns
Type: list
A list of all values found at the specified path.
Examples
Extract all names from a list of objects:
json_path_multi("[*].name", [users])
If users is [{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}], the result is ["Alice", "Bob", "Charlie"].
Filter with a condition:
json_path_multi("$[?age < 30].name", [users])
If users is [{"name": "Alice", "age": 35}, {"name": "Bob", "age": 25}, {"name": "Charlie", "age": 20}], the result is ["Bob", "Charlie"].
Combine with join to produce a string:
join(", ", json_path_multi("[*].email", [contacts]))
If contacts is [{"email": "a@x.com"}, {"email": "b@x.com"}], the result is "a@x.com, b@x.com".
Notes
- Uses the
jsonpath-nglibrary for path resolution, supporting advanced expressions such as wildcards, filters, and recursive descent. - Returns an empty list if no matches are found.
- Use
json_pathinstead if you only need the first matching value or want a fallback for missing data.
Comments
0 comments
Please sign in to leave a comment.