Skip to main content
deleted 20 characters in body; edited tags
Source Link
barbsan
  • 3.5k
  • 11
  • 23
  • 29

I'm using the jq tools (jq-json-processor) in shell script to parse json.

I've got 2 json files and want to merge them into one unique file

Here the content of files:

file1:

{"tag_id" : ["t1"], "inst_id" : "s1"} {"tag_id" : ["t1"], "inst_id" : "s2"} 

file2:

 {"tag_id" : ["t2"], "inst_id" : "s1"}  {"tag_id" : ["t2"], "inst_id" : "s2"}  {"tag_id" : ["t2"], "inst_id" : "s3"} 

expected result:

 {"tag_id" : ["t1","t2"], "inst_id" : "s1"}  {"tag_id" : ["t1","t2"], "inst_id" : "s2"}  {"tag_id" : ["t2"], "inst_id" : "s3"} 

I'm using the jq tools (jq-json-processor) in shell script to parse json.

I've got 2 json files and want to merge them into one unique file

Here the content of files:

file1:

{"tag_id" : ["t1"], "inst_id" : "s1"} {"tag_id" : ["t1"], "inst_id" : "s2"} 

file2:

 {"tag_id" : ["t2"], "inst_id" : "s1"}  {"tag_id" : ["t2"], "inst_id" : "s2"}  {"tag_id" : ["t2"], "inst_id" : "s3"} 

expected result:

 {"tag_id" : ["t1","t2"], "inst_id" : "s1"}  {"tag_id" : ["t1","t2"], "inst_id" : "s2"}  {"tag_id" : ["t2"], "inst_id" : "s3"} 

I'm using the jq tools (jq-json-processor) in shell script to parse json.

I've got 2 json files and want to merge them into one unique file

Here the content of files:

file1:

{"tag_id" : ["t1"], "inst_id" : "s1"} {"tag_id" : ["t1"], "inst_id" : "s2"} 

file2:

{"tag_id" : ["t2"], "inst_id" : "s1"} {"tag_id" : ["t2"], "inst_id" : "s2"} {"tag_id" : ["t2"], "inst_id" : "s3"} 

expected result:

{"tag_id" : ["t1","t2"], "inst_id" : "s1"} {"tag_id" : ["t1","t2"], "inst_id" : "s2"} {"tag_id" : ["t2"], "inst_id" : "s3"} 
Source Link

How to merge json file using jq?

I'm using the jq tools (jq-json-processor) in shell script to parse json.

I've got 2 json files and want to merge them into one unique file

Here the content of files:

file1:

{"tag_id" : ["t1"], "inst_id" : "s1"} {"tag_id" : ["t1"], "inst_id" : "s2"} 

file2:

 {"tag_id" : ["t2"], "inst_id" : "s1"} {"tag_id" : ["t2"], "inst_id" : "s2"} {"tag_id" : ["t2"], "inst_id" : "s3"} 

expected result:

 {"tag_id" : ["t1","t2"], "inst_id" : "s1"} {"tag_id" : ["t1","t2"], "inst_id" : "s2"} {"tag_id" : ["t2"], "inst_id" : "s3"}