从一个 JSON 文件中查找值并替换为另一个文件
Lookup values from one JSON file and replace in another
我有2个文件
1. Translation.json
{
"sKEY": "CustomField.Account.Preferred_Name_Local_Language.Fieldlabel",
"label": "Preferred Name",
"translation": "Nombre Preferido",
}
2。 Form.json
{
"fullName": "Student_Information/Preferred_Name__pc",
"description": "Preferred Name",
"inlineHelpText": "Preferred Name",
"label": "Preferred Name"
}
我需要按 translation.json 中的值查找 "label" 并将 Form.json 中的 "label" 值替换为 translation.json 中的 "tranlsation" 值=].
所述问题有点令人费解,但这里有一个解决方案,假设 jq 是这样调用的:
jq -f program.jq —-argfile dict translation.jq form.json
其中 program.jq 包含:
.label |= if $dict.label == . then $dict.translation else . end
等价于:
if .label == $dict.label then .label = $dict.translation else . end
如果...那么...结束
jq的"master"版本允许if ... then ... end
所以上面的解可以分别简写为:
.label |= if $dict.label == . then $dict.translation end
和:
if .label == $dict.label then .label = $dict.translation end
我有2个文件 1. Translation.json
{
"sKEY": "CustomField.Account.Preferred_Name_Local_Language.Fieldlabel",
"label": "Preferred Name",
"translation": "Nombre Preferido",
}
2。 Form.json
{
"fullName": "Student_Information/Preferred_Name__pc",
"description": "Preferred Name",
"inlineHelpText": "Preferred Name",
"label": "Preferred Name"
}
我需要按 translation.json 中的值查找 "label" 并将 Form.json 中的 "label" 值替换为 translation.json 中的 "tranlsation" 值=].
所述问题有点令人费解,但这里有一个解决方案,假设 jq 是这样调用的:
jq -f program.jq —-argfile dict translation.jq form.json
其中 program.jq 包含:
.label |= if $dict.label == . then $dict.translation else . end
等价于:
if .label == $dict.label then .label = $dict.translation else . end
如果...那么...结束
jq的"master"版本允许if ... then ... end
所以上面的解可以分别简写为:
.label |= if $dict.label == . then $dict.translation end
和:
if .label == $dict.label then .label = $dict.translation end