Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从一个JSON文件中查找值并在另一个JSON文件中替换_Json_Translation_Jq - Fatal编程技术网

从一个JSON文件中查找值并在另一个JSON文件中替换

从一个JSON文件中查找值并在另一个JSON文件中替换,json,translation,jq,Json,Translation,Jq,我有两个文件 1.Translation.json { "sKEY": "CustomField.Account.Preferred_Name_Local_Language.Fieldlabel", "label": "Preferred Name", "translation": "Nombre Preferido", } 二,。Form.json { "fullName": "Studen

我有两个文件 1.Translation.json

        {
       "sKEY": "CustomField.Account.Preferred_Name_Local_Language.Fieldlabel",
       "label": "Preferred Name",
       "translation": "Nombre Preferido",
        }
二,。Form.json

        {
      "fullName": "Student_Information/Preferred_Name__pc",
      "description": "Preferred Name",
      "inlineHelpText": "Preferred Name",
      "label": "Preferred Name"          
        }

我需要按translation.json中的值查找“label”,并用translation.json中的“translation”值替换Form.json中的“label”值。

前面提到的问题有点复杂,但这里有一个解决方案,假设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的“主”版本允许
如果。。。然后。。。结束
,以便将上述解决方案分别缩短为:

.label |= if $dict.label == . then $dict.translation end
以及:


请看这本书并阅读。这两个文档将帮助其他人更快地回答您的问题。实际上translation.json是否由这样的对象数组组成?还是小溪?请澄清。
if .label == $dict.label then .label = $dict.translation end