Applies a jq filter to a string, returning the results as a string.
Parameters:
| Name | Type | Description | Default |
expr | Expression | The expression to apply the jq filter to. | required |
filter | str | | required |
Returns:
| Name | Type | Description |
Expression | Expression | Expression representing the result of the jq filter as a column of JSON-compatible strings. |
Warning
This expression uses jaq as its filter executor which can differ from the jq command-line tool. Please consult jq vs. jaq for a detailed look into possible differences.
Examples:
| >>> import daft
>>> from daft.functions import jq
>>>
>>> df = daft.from_pydict({"col": ['{"a": 1}', '{"a": 2}', '{"a": 3}']})
>>> df.with_column("res", jq(df["col"], ".a")).collect()
|
╭──────────┬────────╮
│ col ┆ res │
│ --- ┆ --- │
│ String ┆ String │
╞══════════╪════════╡
│ {"a": 1} ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ {"a": 2} ┆ 2 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ {"a": 3} ┆ 3 │
╰──────────┴────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 | def jq(expr: Expression, filter: str) -> Expression:
"""Applies a [jq](https://jqlang.github.io/jq/manual/) filter to a string, returning the results as a string.
Args:
expr: The expression to apply the jq filter to.
filter (str): The jq filter to apply.
Returns:
Expression: Expression representing the result of the jq filter as a column of JSON-compatible strings.
Warning:
This expression uses [jaq](https://github.com/01mf02/jaq) as its filter executor which can differ from the
[jq](https://jqlang.org/) command-line tool. Please consult [jq vs. jaq](https://github.com/01mf02/jaq?tab=readme-ov-file#differences-between-jq-and-jaq)
for a detailed look into possible differences.
Examples:
>>> import daft
>>> from daft.functions import jq
>>>
>>> df = daft.from_pydict({"col": ['{"a": 1}', '{"a": 2}', '{"a": 3}']})
>>> df.with_column("res", jq(df["col"], ".a")).collect()
╭──────────┬────────╮
│ col ┆ res │
│ --- ┆ --- │
│ String ┆ String │
╞══════════╪════════╡
│ {"a": 1} ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ {"a": 2} ┆ 2 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ {"a": 3} ┆ 3 │
╰──────────┴────────╯
<BLANKLINE>
(Showing first 3 of 3 rows)
"""
return Expression._call_builtin_scalar_fn("jq", expr, filter=filter)
|