Jq: error: syntax error, unexpected QQSTRING_START, expecting $end

Created on 21 Jan 2014  路  6Comments  路  Source: stedolan/jq

This is with jq v1.3 on OSX 10.9.1.

I'm unable to access a hash key with a double-quoted string (the key contains special characters). A trivial example shows:

$ echo '{"foo": "bar"}' | jq .foo    # without quotes works just fine
"bar"
$ echo '{"foo": "bar"}' | jq '."foo"'    # quoting causes a syntax error
error: syntax error, unexpected QQSTRING_START, expecting $end
."foo"
^
1 compile error

The manual shows almost this exact case:

image

docs support

All 6 comments

Reading through other issues, as well as the manual, and saw the slightly longer .["foo$"] notation. That works. Manual must be out of date.

This should be reopened as the docs are still wrong (or the code still has a bug).

In fact, the docs are too new here - you have to compile jq yourself from master to get the ."foo" notation.

The syntax .foo."bar-baz" worked for me with latest jq (1.5), the one .foo.["bar-baz"] didn't. It seems the docs are incorrect?

Try removing the last dot: .foo["bar-baz"]

@mgol - You are correct that .foo.["bar-baz"] is not supported in 1.5; if you wanted to use the square-bracket notation, you could revert to the more basic expression .foo | .["bar-baz"], or the abbreviated form: .foo["bar-baz"]

The square-bracket notation (i.e. .[ ACCESSOR ] where ACCESSOR is an expression that evaluates to a JSON string or integer) is actually the fundamental one (i.e. supported by jq 1.3, 1.4, 1.5 and possibly others).

Could you please specify exactly which part of the documentation you believe to be incorrect?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kaihendry picture kaihendry  路  4Comments

tbelaire picture tbelaire  路  4Comments

ghost picture ghost  路  4Comments

kelchy picture kelchy  路  4Comments

ve3ied picture ve3ied  路  4Comments