owenthereal / jqplay

A playground for jq, written in Go
https://jqplay.org
MIT License
734 stars 87 forks source link

error when key contains minus character #129

Closed Dikowda closed 1 year ago

Dikowda commented 1 year ago

Jqplay is unable to extract data from keys which include minus character. Example. .ba-r returns

jq: error: r/0 is not defined at , line 1: .foo,.ba-r
jq: 1 compile error exit status 3 see https://jqplay.org/s/QOlzb6BzZCr

I than seen api's return json with keys like this.

SubOptimal commented 1 year ago

Surround the field name with double-quotes .foo,."ba-r".

An example for the command line for demonstration.

$ echo '{ "foo": 42, "ba-r": "something else", "baz": true}' | jq '.foo,.ba-r'
jq: error: r/0 is not defined at <top-level>, line 1:
.foo,.ba-r         
jq: 1 compile error

$ echo '{ "foo": 42, "ba-r": "something else", "baz": true}' | jq '.foo,."ba-r"'
42
"something else"
Dikowda commented 1 year ago

@SubOptimal thanks,

Kinda obvious. I should have looked at the manual image