Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 527

Convert bash array to json array and insert to file using jq

$
0
0

Given a bash array, how to convert it to a JSON array in order to output to a file with jq?

Additionnally: is there a way to keep the server_nohup array unchanged instead of re-writing the whole json file each time?

newArray=(100 200 300)jq -n --arg newArray $newArray '{    client_nohup: [         $newArray    ],    server_nohup: [    ]}'> $projectDir/.watch.json

Current output:

{"client_nohup": ["100"],"server_nohup": []}

Desired output:

{"client_nohup": [    100,    200,    300],"server_nohup": []}

Viewing all articles
Browse latest Browse all 527

Trending Articles