【发布时间】:2021-11-12 11:43:25
【问题描述】:
json 的每个键都应与_(或任何有效的 json 符号)结合。拥有一个简单的键值列表。
我有以下结构。一些 json 组(没有数组),在组中有键值对。我需要将它们扁平化为一个键值列表。我试过jq,但只有某事。 “嵌套”/“未嵌套”。我没找到。关于压平或组合键。
所以应该是"key_subkey_subsubkey": "value"
{
"welcome": {
"title" : "Hello World"
},
"block1": {
"header": "My Header",
"body": "My BODY of block 1",
"footer": "My Footer"
},
"multi": {
"level-01-A": {
"head": "Head Section",
"foot": "Foot Section"
"level-02-A": {
"head": "Head Section Level 2 A",
"fead": "Foot Section Level 2 A"
},
"level-02-B": {
"head": "Head Section Level 2 B",
"fead": "Foot Section Level 2 B"
},
},
"level-01-B": {
"head": "Head Section",
"foot": "Foot Section"
}
"no-level" : "Foo Bar",
}
}
我想拥有
{
"welcome_title" : "Hello World",
"block1_header": "My Header",
"block1_body": "My BODY of block 1",
"block1_footer": "My Footer",
"multi_level-01-A_head": "Head Section",
"multi_level-01-A_foot": "Foot Section",
"multi_level-01-A_level-02-A_head": "Head Section Level 1 A",
"multi_level-01-A_level-02-A_fead": "Foot Section Level 1 A",
"multi_level-01-A_level-02-B_head": "Head Section Level 1 B",
"multi_level-01-A_level-02-B_fead": "Foot Section Level 1 B",
"multi_level-01-B_head": "Head Section",
"multi_level-01-B_foot": "Foot Section",
"multi_no-level" : "Foo Bar"
}
任何想法,我可以使用什么工具?
【问题讨论】: