Skip to content

fix format string as object key in object construction and pattern - #348

Closed
akasakariko wants to merge 1 commit into
itchyny:mainfrom
akasakariko:format-string-object-key
Closed

akasakariko wants to merge 1 commit into
itchyny:mainfrom
akasakariko:format-string-object-key

Conversation

@akasakariko

@akasakariko akasakariko commented Nov 29, 2026 •

Copy link
Copy Markdown

jq accepts a format string such as @sh "a" as an object key in object construction and object patterns
gojq rejected these queries because objectkeyval and objectpattern only accepted a plain string
This adds an optional tokFormat before the string in both rules and stores the format in String, so the key prints and compiles like a regular string key with the format applied to interpolations only

Closes #345

@itchyny

itchyny commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Thank you for working on this. However, this PR doesn't fix the root cause: jq's grammar treats a format string as a kind of string, so it's accepted everywhere a string is, including indexing without brackets. Adding rules for each place only covers the symptoms. Duplicating the logic for compiling formats (in compileFormat/compileString) is very confusing. Superseded by 562bad1, which treats a format as a string in the grammar, as jq does. So closing this PR.

@itchyny itchyny closed this Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A format string as an object key is a syntax error (accepted by jq and jaq)

2 participants