Jq: Can dashes be escaped in entity names?

Created on 24 Oct 2013  路  4Comments  路  Source: stedolan/jq

This may just be a lack of my understanding, but while trying to parse a response to get tag values for a tagname, unfortunately someone used a dash in one of the tagnames which is interpreted by jq. Is there any way to escape this from being interpreted by jq?

I used something like this:

jq '.queries[0] | .results[0] | .tags | .bad-tag | .[]'

..where bad-tag doesn't work. I've also tried: .["bad-tag"] and various other things to try to work around it, but can't find a solution..

Any suggestions?

support

Most helpful comment

Found the solution on this page:

cat info.json | jq --raw-output '.messages[0] | .headers | .["user-agent"] '

All 4 comments

Actually, I think it does work. I hadn't escaped the variable I used properly in the shell script.

Thanks.

How did you get this to work, please? I have the following problem using a dash in a tag name:

$ cat info.json | jq --raw-output '.messages[0] | .headers | .user-agent '
error: agent is not defined
.messages[0] | .headers | .user-agent
                                ^^^^^
1 compile error

I've tried using backslashes, HTML escapes, and @ symbols.

Found the solution on this page:

cat info.json | jq --raw-output '.messages[0] | .headers | .["user-agent"] '

Right, that's what I did..

Cheers.

On Wed, Apr 02, 2014 at 12:56:52PM -0700, Steve Onetwothreefourfivesix wrote:

Found the solution on this page:

cat info.json | jq --raw-output '.messages[0] | .headers | .["user-agent"] '

Reply to this email directly or view it on GitHub:
https://github.com/stedolan/jq/issues/202#issuecomment-39375869

Bill Duncan,
[email protected]
+1 416 697-9315

Was this page helpful?
0 / 5 - 0 ratings