jsawk icon indicating copy to clipboard operation
jsawk copied to clipboard

Parse error when key name starts with a number

Open Tomaskom-cz opened this issue 8 years ago • 1 comments

jsawk fails to extract a value for a key when it's name starts with a number. (or name of any key in the chain)

This works fine:

echo '{"val1":"v1","2val":"v2"}' | ./jsawk "return this.val1"
v1

This fails:

echo '{"val1":"v1","2val":"v2"}' | ./jsawk "return this.2val"
jsawk: script parse error: 'return this.2val'

Tomaskom-cz avatar Apr 25 '16 01:04 Tomaskom-cz

You can escape the key with brackets:

echo '{"val1":"v1","2val":"v2"}' | jsawk "return this['2val']"

guido4000 avatar May 19 '16 19:05 guido4000