Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQ: error: syntax error, unexpected INVALID_CHARACTER, expecting $end

Tags:

jq

I am calling jq on the command line in Linux like this:

jq -s -R -f get.jq get-config.txt

which returns:

error: syntax error, unexpected INVALID_CHARACTER, expecting $end
.1 compile error

But there is only a dot in get.jq file to test like

jq -s -R . get-config.txt

Which returns fine. So what's wrong with the jq file?

like image 589
Nic Avatar asked Nov 15 '15 16:11

Nic


1 Answers

I get a very similar error when I use MS Windows line endings. For example, prepare a couple of files, id.jq with sane Unix line endings and id-ms.jq with Microsoft's CP/M style CR-LF line endings, and finally id-utf8bom.jq with a Unix line endings and a UTF-8 BOM:

printf '.\n' > id.jq
printf '.\r\n' > id-ms.jq
printf '\xef\xbb\xbf.\n' > id-utf8bom.jq

and the Unix version succeeds:

echo true | jq -f id.jq

while the file with carriage return and line feeds for new lines:

echo true | jq -f id-ms.jq

causes jq (version 1.6) to fail with:

jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at <top-level>, line 1:

jq: error: try .["field"] instead of .field for unusually named fields at <top-level>, line 1:
.
jq: 2 compile errors

and the version with a UTF-8 BOM version:

echo true | jq -f id-utf8bom.jq

gives a more limited error message:

jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
.
jq: 1 compile error

would be great if it recognised / handled these relatively common encodings, but it doesn't seem to at the moment!

like image 67
Sam Mason Avatar answered Nov 03 '22 10:11

Sam Mason