Skip to content

Failure to parse .x.["y.z"] notation #1168

Closed
@mcint

Description

@mcint

mcint@work MINGW64 /c/git

The document

$ less test.json | jq -c '.'
{"a":"A","b":{"c":{"d.e.f":"DEF"}}}

The complex key

$ less test.json | jq -c '.b.c'
{"d.e.f":"DEF"}

One naive approach

$ less test.json | jq -c '.b.c.d.e.f'
null

Solution proposed by the docs

$ less test.json | jq -c '.b.c.["d.e.f"]'
jq: error: syntax error, unexpected '[', expecting FORMAT or QQSTRING_START (Windows cmd shell quoting issues?) at <top-level>, line 1:
.b.c.["d.e.f"]
jq: 1 compile error

Work-around

$ less test.json | jq -c '.b.c | .["d.e.f"]'
"DEF"

Boundaries of quoted key solution

$ less test.json | jq -c '.b | .c.["d.e.f"]'
jq: error: syntax error, unexpected '[', expecting FORMAT or QQSTRING_START (Windows cmd shell quoting issues?) at <top-level>, line 1:
.b | .c.["d.e.f"]
jq: 1 compile error

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions