Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have 2 files 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"          
        }

I need to lookup the "label" by value in translation.json and replace the "label" value in Form.json with the "tranlsation" value from translation.json.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
249 views
Welcome To Ask or Share your Answers For Others

1 Answer

The problem as stated is a bit perplexing, but here is a solution, assuming that jq is invoked like so:

jq -f program.jq —-argfile dict translation.jq form.json

where program.jq contains:

.label |= if $dict.label == . then $dict.translation else . end

Equivalently:

if .label == $dict.label then .label = $dict.translation else . end

if ... then ... end

The "master" version of jq allows if ... then ... end so that the above solutions can be respectively shortened to:

.label |= if $dict.label == . then $dict.translation end

and:

if .label == $dict.label then .label = $dict.translation end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...