Using Apache Spark in Java, I have:
root
|-- datasetid: string (nullable = true)
|-- fields: struct (nullable = true)
...
| |-- latlon: array (nullable = true)
| | |-- element: double (containsNull = true)
This is based on this JSON fragment:
"fields":{
"latlon":[
35.9543748,
-78.9944911
],
I was trying to extract the data to a column using:
df = df.withColumn("lat", df.col("fields.latlon[0]"));
df = df.withColumn("lon", df.col("fields.latlon[1]"));
(I hope you appreciate the neatness of the syntax). However, I must admit it does not really work:
No such struct field latlon[1] in
I tried a few other things without much luck...