Skip to content

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.
These dots are for future extensions and must be empty.
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

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  json_val = c('{"a":1, "b": true}', NA, '{"a":2, "b": false}')
)
dtype <- pl$Struct(a = pl$Int64, 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} │
#> └───────────┘