I have a JSON that looks like this:
"mapping_field" : {
"values" : {
"key1" : {
"id" : "key1",
"field1" : "value1",
"field2" : "value2",
},
"key2" : {
"id" : "key2",
"field1" : "value3",
"field2" : "value4",
}
},
"keys" : [
"key1",
"key2"
]
}
I am trying to map this structure to a Spark Schema. I have already created the following; however it's not working. I have also tried removine the ArrayType in the Values field mapping.
StructType("mapping_field",
MapType(
StructField("keys", ArrayType(StringType())),
StructField("values", ArrayType(StructType([
StructField("id",StringType()),
StructField("field1",StringType()),
StructField("field2",StringType())
])))
)
)
Also, please note they “key1” and “key2” are dynamic fields that will be generated with a unique identifier. There can also be more than two keys. Has anyone been able to map ArrayType to StructType?