Skip to main content
quotes
Source Link
peak
  • 119.1k
  • 21
  • 185
  • 218

It looks as though you simply want to set .ENV.DEV in the first file to .ENV.DEV in the second. If so, then assuming the contents of the second file is somehow in the jq variable $f2, all you need is an assignment statement:

.ENV.DEV = $f2.ENV.DEV 

So, if you don't mind using --argfile, you could write:

jq --argfile f2 jsonFile2.json '.ENV.DEV=$f2.ENV.DEV' jsonFile1.json 

This at least gives the expected result (modulo some technical issues in the given sample).

Since --argfile is technically deprecated, you might wish to use --slurpfile instead, and I could imagine you might want to use +=, but unless you really know what using '' or '='* or *= implies, I'd avoid them.

It looks as though you simply want to set .ENV.DEV in the first file to .ENV.DEV in the second. If so, then assuming the contents of the second file is somehow in the jq variable $f2, all you need is an assignment statement:

.ENV.DEV = $f2.ENV.DEV 

So, if you don't mind using --argfile, you could write:

jq --argfile f2 jsonFile2.json '.ENV.DEV=$f2.ENV.DEV' jsonFile1.json 

This at least gives the expected result (modulo some technical issues in the given sample).

Since --argfile is technically deprecated, you might wish to use --slurpfile instead, and I could imagine you might want to use +=, but unless you really know what using '' or '=' implies, I'd avoid them.

It looks as though you simply want to set .ENV.DEV in the first file to .ENV.DEV in the second. If so, then assuming the contents of the second file is somehow in the jq variable $f2, all you need is an assignment statement:

.ENV.DEV = $f2.ENV.DEV 

So, if you don't mind using --argfile, you could write:

jq --argfile f2 jsonFile2.json '.ENV.DEV=$f2.ENV.DEV' jsonFile1.json 

This at least gives the expected result (modulo some technical issues in the given sample).

Since --argfile is technically deprecated, you might wish to use --slurpfile instead, and I could imagine you might want to use +=, but unless you really know what using * or *= implies, I'd avoid them.

Source Link
peak
  • 119.1k
  • 21
  • 185
  • 218

It looks as though you simply want to set .ENV.DEV in the first file to .ENV.DEV in the second. If so, then assuming the contents of the second file is somehow in the jq variable $f2, all you need is an assignment statement:

.ENV.DEV = $f2.ENV.DEV 

So, if you don't mind using --argfile, you could write:

jq --argfile f2 jsonFile2.json '.ENV.DEV=$f2.ENV.DEV' jsonFile1.json 

This at least gives the expected result (modulo some technical issues in the given sample).

Since --argfile is technically deprecated, you might wish to use --slurpfile instead, and I could imagine you might want to use +=, but unless you really know what using '' or '=' implies, I'd avoid them.