Jq: escape chars

Created on 3 Nov 2012  路  9Comments  路  Source: stedolan/jq

How can I escape "$" char?
I'm trying to parse the youtube apis, getting this _media$group_
This work

  curl 'https://gdata.youtube.com/feeds/api/standardfeeds/IT/most_recent_Sports/?v=2&alt=json' | jq' .feed.entry[] | {title}'

This is not working:

  curl 'https://gdata.youtube.com/feeds/api/standardfeeds/IT/most_recent_Sports/?v=2&alt=json' | jq' .feed.entry[] |  {media$group}'
support

Most helpful comment

@theoreticaLee you can use keys with slashes, but you'll have to use explicit strings as the keys:

jq '.slash/key' won't work, but jq '.["slash/key"]' will.
jq '{slash/key}' won't work, but jq '{"slash/key"}' will.

All 9 comments

Along the same lines - I'm getting errors when the keys I'm trying to query for have '.' or ':' in them - ie/ 'foo.bar.baz:8008' is a key I'm trying to pull out out some JSON.

You can use the following syntax:

jq '.feed.entry[] | {"group": .["media$group"]}'

The {foo} syntax is shorthand for this, but you need to use the longhand version if there are unusual characters in the field name.

ok, thanks for your answer

Now (if you build master) you can use:

jq '.feed.entry[] | {"media$group"}'

Yeah, it would be great to add in escaping ability. I'm running into trouble with facebook's api as some results have keys with forward slash in them :/

@theoreticaLee you can use keys with slashes, but you'll have to use explicit strings as the keys:

jq '.slash/key' won't work, but jq '.["slash/key"]' will.
jq '{slash/key}' won't work, but jq '{"slash/key"}' will.

@theoreticaLee you can use keys with slashes, but you'll have to use explicit strings as the keys:

jq '.slash/key' won't work, but jq '.["slash/key"]' will.
jq '{slash/key}' won't work, but jq '{"slash/key"}' will.

honestly love that one : just so useful today, using hashicorp vault api...

@Jean-Baptiste-Lasselle I'm dealing with the same thing, in the list of accessors at sys/auth

None of the above solutions worked, I had to generate a jqparams.txt file using a "heredoc" and put environment variables in it, then pass that using jq --from-file jqparams.txt.

Would be nice to see this program play better with bash primitives.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neowulf picture neowulf  路  3Comments

kelchy picture kelchy  路  4Comments

tbelaire picture tbelaire  路  4Comments

sonots picture sonots  路  3Comments

lbrader picture lbrader  路  3Comments