daft.Expression.json.query

daft.Expression.json.query#

Expression.json.query(jq_query: str) Expression[source]#

Query JSON data in a column using a JQ-style filter https://jqlang.github.io/jq/manual/ This expression uses jaq as the underlying executor, see 01mf02/jaq for the full list of supported filters.

Example

>>> df = daft.from_pydict({"col": ['{"a": 1}', '{"a": 2}', '{"a": 3}']})
>>> df.with_column("res", df["col"].json.query(".a")).collect()
╭──────────┬──────╮
│ col      ┆ res  │
│ ---      ┆ ---  │
│ Utf8     ┆ Utf8 │
╞══════════╪══════╡
│ {"a": 1} ┆ 1    │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ {"a": 2} ┆ 2    │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ {"a": 3} ┆ 3    │
╰──────────┴──────╯
Parameters:

jq_query (str) – JQ query string

Returns:

Expression representing the result of the JQ query as a column of JSON-compatible strings

Return type:

Expression