Anmol Singh
10/05/2024, 5:51 AMDesmond Cheong
10/05/2024, 6:02 AMAnmol Singh
10/05/2024, 6:16 AMDesmond Cheong
10/05/2024, 8:21 AM{
"a": 1,
"b": {
"c": 3,
"d": [
1.1,
2.2,
3.3
]
}
}
that we can read
>>> daft.read_json("my.json").collect()
╭───────┬────────────────────────────────────╮
│ a ┆ b │
│ --- ┆ --- │
│ Int64 ┆ Struct[c: Int64, d: List[Float64]] │
╞═══════╪════════════════════════════════════╡
│ 1 ┆ {c: 3, │
│ ┆ d: [1.1, 2.2, 3.3], │
│ ┆ } │
╰───────┴────────────────────────────────────╯
(Showing first 1 of 1 rows)
or alternatively, let's say you have a string column that you want to treat as json with nested json objects, you can also use our .json.query expression to query the json column
>>> import daft
>>> df = daft.from_pydict({"col": ['{"a": 1, "b": {"c": 2}}', '{"a": 2, "b": {"c": 20}}', '{"a": 3, "b": {"c": 300}}']})
>>> df.with_column("res", df["col"].json.query(".b.c")).collect()
╭───────────────────────────┬──────╮
│ col ┆ res │
│ --- ┆ --- │
│ Utf8 ┆ Utf8 │
╞═══════════════════════════╪══════╡
│ {"a": 1, "b": {"c": 2}} ┆ 2 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ {"a": 2, "b": {"c": 20}} ┆ 20 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ {"a": 3, "b": {"c": 300}} ┆ 300 │
╰───────────────────────────┴──────╯
(Showing first 3 of 3 rows)
(see https://www.getdaft.io/projects/docs/en/latest/api_docs/doc_gen/expression_methods/daft.Expression.json.query.html#daft-expression-json-query for more details)Anmol Singh
10/08/2024, 6:08 AMDesmond Cheong
10/10/2024, 3:42 AM