2017-03-27 51 views
2

我有一個result.json用命令行JQ另一個JSON文件替換JSON節點

{ 
    "Msg": "This is output", 
    "output": {} 
} 

output.json

{ 
    "type": "string", 
    "value": "result is here" 
} 

我想整個文件output.json作爲替換result.jsonoutput

{ 
    "Msg": "This is output", 
    "output": { 
     "type": "string", 
     "value": "result is here" 
    } 
} 

jq命令行的想法?先謝謝你。

回答

2

您可以使用--argfile處理多個文件:

jq --argfile f1 result.json --argfile f2 output.json -n '$f1 | .output = $f2' 
2

基本上一樣貝特朗Martel的答案,但使用不同的(較短)的方式來閱讀這兩個文件。

jq -n 'input | .output = input' result.json output.json 
+0

偉大的,作爲魅力,只是想知道我怎麼能找到一些全面的教程jq,我GOOGLE了,但沒有好運氣。 – perigee

+0

沒有我所知道的。手冊頁是好的,但可以擴展一些觀點。 (例如,流媒體對我來說仍然是一個完全謎。) – chepner

+0

thx很多,真的很感激 – perigee

相關問題