Given the following xample.json
;
[
{
\"id\": 12345678,
\"stuff\": { \"book\": \"shelf\", \"hook\": \"line\", \"took\": \"off\", \"info-spec
interesting, the issue is indeed the "-" character and this works for me:
jq '.[] | { id, "info-spec": .stuff."info-spec" }' xample.json
{
"id": 12345678,
"info-spec": 12
}
{
"id": 12345679,
"info-spec": 23
}
yet your jq
does not seem to like that syntax as it broke on the following and mine does not:
jq '.[] | .stuff."info-spec"' xample.json
12
23
I use:
jq --version
jq-1.4
edit: looks like a version issue with <1.4 indeed: https://github.com/stedolan/jq/issues/38
I managed to figure it out.
$ jq '.[] | { id, "info-spec": .stuff["info-spec"] }' xample.json
{
"info-spec": 12,
"id": 12345678
}
{
"info-spec": 23,
"id": 12345679
}
The key here seems to be to use the newkey: .complex["key"]
notation for lifting.