Kopīgot, izmantojot


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

from pyspark.sql import functions as sf

sf.json_array_length(col)

Parameters

Parameter Type Description
col pyspark.sql.Column or str Target column to compute on.

Returns

pyspark.sql.Column: length of json array.

Examples

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()
[Row(r=None), Row(r=3), Row(r=0)]