Parse string values as JSON.
Description
Parse string values as JSON.
Usage
<Expr>$str$json_decode(dtype, infer_schema_length = 100)
Arguments
dtype
|
The dtype to cast the extracted value to. If NULL , the
dtype will be inferred from the JSON value.
|
infer_schema_length
|
How many rows to parse to determine the schema. If NULL ,
all rows are used.
|
Details
Throw errors if encounter invalid json strings.
Value
Expr returning a struct
Examples
library("polars")
df = pl$DataFrame(
json_val = c('{"a":1, "b": true}', NA, '{"a":2, "b": false}')
)
dtype = pl$Struct(pl$Field("a", pl$Int64), pl$Field("b", pl$Boolean))
df$select(pl$col("json_val")$str$json_decode(dtype))
#> shape: (3, 1)
#> ┌───────────┐
#> │ json_val │
#> │ --- │
#> │ struct[2] │
#> ╞═══════════╡
#> │ {1,true} │
#> │ null │
#> │ {2,false} │
#> └───────────┘