jqlang / jq

Command-line JSON processor
https://jqlang.github.io/jq/
Other
30.23k stars 1.57k forks source link

Cannot select sub-field that has a dash in the name of the field #3100

Closed brucejo75 closed 5 months ago

brucejo75 commented 5 months ago

Describe the bug .["Cache-Control"] works .resp_header.["Cache-Control"] does not work

To Reproduce See https://jqplay.org/s/EhUZ6-UcIae

Data for repro (also available in `jq play`) json input: ```json { "resp_headers": { "Cache-Control:": ["max-age=2592000; public;"] }, "Cache-Control": ["max-age=2592000; public;"] } ``` jq filter: ```jq { "Cache-Control": .resp_headers.["Cache-Control"], "C-CA": .resp_headers["Cache-Control"], "C-CB": .resp_headers."Cache-Control", "resp_headers": .resp_headers, "C-C2A": .["Cache-Control"], "C-C2B": ."Cache-Control" } ``` result: ```json { "Cache-Control": null, "C-CA": null, "C-CB": null, "resp_headers": { "Cache-Control:": [ "max-age=2592000; public;" ] }, "C-C2A": [ "max-age=2592000; public;" ], "C-C2B": [ "max-age=2592000; public;" ] } ```

Expected Output

{
  "Cache-Control": [
    "max-age=2592000; public;"
  ],
  "C-CA": [
    "max-age=2592000; public;"
  ],
  "C-CB": [
    "max-age=2592000; public;"
  ],
  "resp_headers": {
    "Cache-Control:": [
      "max-age=2592000; public;"
    ]
  },
  "C-C2A": [
    "max-age=2592000; public;"
  ],
  "C-C2B": [
    "max-age=2592000; public;"
  ]
}

Environment (please complete the following information):

Additional context Related #38

brucejo75 commented 5 months ago

D'oh field was "Cache-Control:" not "Cache-Control". jq works fine.

Closing