jqlang / jq

Command-line JSON processor

Home Page:https://jqlang.github.io/jq/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strange behaviour when a key is like E[0-9]*

joakinen opened this issue · comments

Hi,

It seems that if a key starts with the letter "E" and the rest of the key name consists of numbers that key is processed as an error.

$ jq --version
jq-1.5
$ echo "{\"S0\":\"bar\"}" | jq .S0
"bar"
$ echo "{\"E0\":\"bar\"}" | jq .E0
jq: error: Invalid numeric literal at EOF at line 1, column 3 (while parsing '.E0') at <top-level>, line 1:
.E0
jq: 1 compile error

Thanks for reporting the bug. As you've noticed, jq tries to parse tokens such as .E0, .e0, .e1, etc, as numbers and hence the error message.

For those seeking a workaround, it is, as always with problematic key names, to use the primary accessor syntax:.["KEY"]

hi @joakinen
The scenario you mentioned can already be handled correctly.you can try it in master branch.

root@os-001: echo '{"a0":123}' | jq .a0
123
root@os-001: echo '{"C0":123}' | jq .C0
123
root@os-001: echo '{"R0123":123}' | jq .R0123
123

Yes, this is a bug, and a dup of a number of earlier bugs.