【发布时间】:2021-10-20 04:42:27
【问题描述】:
需要像下面这样解析下面的Json-
新的.json
{
"name": "johnDoe",
"dept": 45,
"details": [
{
"salary": "76566",
"weight": "150",
"height": "160",
"sex": "male",
"country": "Usa",
"State": "NJ"
},
{
"salary": "76560",
"weight": "160",
"height": "180",
"sex": "male",
"country": "Usa",
"State": "NC"
}
]
}
{
"name": "DanLee",
"dept": 46,
"details": [
{
"salary": "76566",
"weight": "180",
"height": "160",
"sex": "male",
"country": "Usa",
"State": "NJ"
},
{
"salary": "76560",
"weight": "190",
"height": "180",
"sex": "male",
"country": "Usa",
"State": "NC"
},
{
"salary": "87888",
"weight": "170",
"height": "160",
"sex": "male",
"country": "Usa",
"State": "NY"
}
]
}
需要从上述Json格式中提取名称、体重和状态信息,并得到一个逗号分隔的文件进行分析,如下所示:
name,weight,State
johnDoe,150,NJ
johnDoe,160,NC
DanLee,180,NJ
DanLee,190,NC
DanLee,170,NY
我刚刚开始在 Linux 中使用 Jq,想通过一步一步的解释来了解如何进行这种转换。
谢谢。
【问题讨论】:
-
您的 JSON 输入缺少相当多的标点符号以使其成为有效的 JSON。