Reputation: 3
How to append value to json key using?
val=""text"",""text"",""text""
jq '.doc[1].DEF[3].value="update comma separated val here" <<< "$jsonStr"
Upvotes: 0
Views: 447
Reputation: 295413
If your goal is to split a string on commas to generate a list, and use your list in jq, that might look like:
val=text1,text2,text3
jq --arg val "$val" '.whatever.item |= ($val | split(","))' <<<'{"whatever": {}}'
Note:
jq
argument --arg
is used to pass that variable from a shell context to a jq context.|=
construct is used to modify a nested value while still evaluating to the larger document.Upvotes: 2