jq can't search keynames that include colons. This is a big problem for hiera/puppet users since they often have keynames in the form of function::parameter
To reproduce:
$ cat x.json
{
"first": "value1",
"key::name": "value2"
}
$ jq <x.json '.first'
"value1"
$ jq <x.json '.key::name'
error: syntax error, unexpected ':', expecting $end
.key::name
^
1 compile error
$
The .foo.bar syntax only accepts a limited set of characters. Try .["foo"]["bar"], or, in recent versions, ."foo"."bar". In your case, that would be .["key::name"]
Ok. This works. Can you update the docs? I think a lot of Puppet users would appreciate it because they'll be looking for that too.
jq <x.json '.["key::name"]'
(this works in jq version 1.3)
It is mentioned pretty thoroughly on the manual.
.foo,.foo.barIf the key contains special characters, you need to surround it with double quotes like this:
."foo$".
.[<string>],.[2],.[10:15]You can also look up fields of an object using syntax like
.["foo"](.fooabove is a shorthand version of this).
Contributions and improvements to the docs are welcome and heavily encouraged, but I'm not sure about what to change.
Perhaps the tutorial and manual should both list the .["key"] or ."key"
syntax first, _then_ point out that .key is a handy shorter form, rather
than the inverse.
That sounds like a good idea.
TBH, when I read that I didn't see the benefit of .["key"]. It just seemed like more typing for no purpose. Having an explicit example of a key that wouldn't work in the short form would make it more clear.
Most helpful comment
It is mentioned pretty thoroughly on the manual.
Contributions and improvements to the docs are welcome and heavily encouraged, but I'm not sure about what to change.