Skip to content

Extract the first match of JSON string with the provided JSONPath expression

Source code

Description

Extract the first match of JSON string with the provided JSONPath expression

Usage

<Expr>$str$json_path_match(json_path)

Arguments

json_path A valid JSON path query string.

Details

Throw errors if encounter invalid JSON strings. All return value will be cast to String regardless of the original value.

Documentation on JSONPath standard can be found here: https://goessner.net/articles/JsonPath/.

Value

String array. Contain null if original value is null or the json_path return nothing.

Examples

library(polars)

df = pl$DataFrame(
  json_val = c('{"a":"1"}', NA, '{"a":2}', '{"a":2.1}', '{"a":true}')
)
df$select(pl$col("json_val")$str$json_path_match("$.a"))
#> shape: (5, 1)
#> ┌──────────┐
#> │ json_val │
#> │ ---      │
#> │ str      │
#> ╞══════════╡
#> │ 1        │
#> │ null     │
#> │ 2        │
#> │ 2.1      │
#> │ true     │
#> └──────────┘