How can I explode the nested JSON data where no name struct /array exist in schema?
For example:
root
|-- items: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- street: array (nullable = true)
| | | |-- element: struct (containsNull = true)
| | | | |-- data: array (nullable = true)
| | | | | |-- element: struct (containsNull = true)
| | | | | | |-- statistic: struct (nullable = true)
| | | | | | | |-- a: long (nullable = true)
| | | | | | | |-- b: long (nullable = true)
| | |
|-- name: John
|-- age:24
The schema using JSON schema reader in Notepad++
items
-[0]:objects
-street:[array]
-[0]:objects
-statistics:[object]
I tried to load the data into dataframe (using multiline) and then temp table and tried to query.
spark.sql("select explode(items) as new_item from TempView").show(1,True)this returns an array but not in tabular form as expected.explodealso didn't work. Could you please help me how can I get into "statistic" as the node object don't have any name to explode. (It has [0].) I want to load the statistic data into table.
df.select(F.col('items')[0]['street'][0]['data'][0]['statistic']).show()?