Skip to content

Improve JSON key parsing#3141

Merged
coheigea merged 1 commit into
mainfrom
coheigea/json-key
May 25, 2026
Merged

Improve JSON key parsing#3141
coheigea merged 1 commit into
mainfrom
coheigea/json-key

Conversation

@coheigea
Copy link
Copy Markdown
Contributor

When parsing a JSON key name, the parser used a simple "find the next " character" search. This meant if a key contained an escaped quote — like "foo"bar" — the parser would stop at the " inside the key and think the key had already ended. It would extract foo\ as the key name instead of the correct foo"bar, then get confused about where the value was.

  • Find the closing quote correctly. Instead of stopping at the first " it sees, the parser now counts how many backslashes come immediately before each ". An odd number of backslashes means the quote is escaped (it's part of the key, keep going); an even number means those backslashes are paired escape sequences and the " is the real end of the key.
  • Unescape the key name. After finding the correct boundary, the raw content foo"bar is decoded — " becomes " — so the key stored in the map is the actual intended string foo"bar.

@coheigea coheigea merged commit bc86f63 into main May 25, 2026
5 checks passed
@coheigea coheigea deleted the coheigea/json-key branch May 25, 2026 14:50
coheigea added a commit that referenced this pull request May 25, 2026
(cherry picked from commit bc86f63)
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.

2 participants