Eu tenho uma matriz de objetos parecida com esta:
[
{"host": "1.exampl.com", "path": "/dir1/file.html"},
{"host": "2.exampl.com", "path": "/dir2/file.html"},
{"host": "3.exampl.com", "path": "/dir3/file.html"}
]
e quero adicionar uma nova chave em cada um desses objetos, que criará a URL usando o host e o caminho, então ficaria assim:
[
{"host": "1.exampl.com", "path": "/dir1/file.html", "url": "http://1.example.com/dir1/file.html"},
{"host": "2.exampl.com", "path": "/dir2/file.html", "url": "http://2.example.com/dir2/file.html"},
{"host": "3.exampl.com", "path": "/dir3/file.html", "url": "http://3.example.com/dir3/file.html"}
]
como posso fazer isso usando jq
.
Tentei fazer ".[] |= . { . + {\"url\": \"http://\" + .host + .path } }"
mas não funcionou e retornou este erro:
jq: error: syntax error, unexpected '}', expecting $end (Unix shell quoting issues?) at <top-level>, line 1: