【发布时间】:2021-11-05 01:23:53
【问题描述】:
我有以下 json:
{
"data": {
"data2": [],
"data3": [
{
"info": {
"test1": "value1",
"test2": "value2"
},
"info2": [
{
"info": {
"test1": "value3",
"test2": "value4"
},
{
"info": {
"test1": "value5",
"test2": "value6"
}
]
}
]
}}
我需要将 info2.info.test1、info2.info.test2 提取到列中。 我已经在火花中解析了它,但我有一个数组列而不是单行:
df = json.select(
explode("data.data3.info2").alias("json"),
).select(
col("json.info.test1"),
col("json.info.test2")
)
预期输出:
| test1 | test2 |
| -------- | -------------- |
| value3 | value4 |
| value5 | value6 |
【问题讨论】:
-
您能检查一下您提供的 JSON 文件吗?看起来它已经损坏了。顺便说一句,很高兴看到预期的输出。
-
您的 json 似乎是错误的,请您仔细检查一下并告知预期的输出如何?
-
我已添加更改,感谢 cmets。
标签: json apache-spark pyspark jsonparser