json_array_length
Returns the number of elements in the outermost JSON array. NULL is returned in case of any other valid JSON string, NULL or an invalid JSON.
Syntax
Python
from pyspark.sql import functions as sf
sf.json_array_length(col)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Target column to compute on. |
Returns
pyspark.sql.Column: length of json array.
Examples
Python
from pyspark.sql import functions as sf
df = spark.createDataFrame([(None,), ('[1, 2, 3]',), ('[]',)], ['data'])
df.select(sf.json_array_length(df.data).alias('r')).collect()
Output
[Row(r=None), Row(r=3), Row(r=0)]