Skip to content

Fix ParserError#json_path with symbolize_names: true - #1118

Merged
byroot merged 1 commit into
ruby:masterfrom
sebxt:fix/json-path-symbolize-names
Oct 19, 2026
Merged

byroot merged 1 commit into
ruby:masterfrom
sebxt:fix/json-path-symbolize-names

Conversation

@sebxt

@sebxt sebxt commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

When a document is parsed with symbolize_names: true, the object keys recorded for json_path are Symbols. Since #1113, build_json_path calls valid_encoding? on each key segment, which Symbol does not implement, so error.json_path raised NoMethodError instead of returning the path:

JSON.parse('{"a": [1, {"b": xyz}]}', symbolize_names: true)
# error.json_path => NoMethodError: undefined method 'valid_encoding?' for an instance of Symbol

This converts the segment to a String before the encoding and identifier checks. A test covers a nested path, a quoted key and a nested duplicate key with symbolize_names: true. A CHANGES.md entry is included.

Fixes #1117

Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
@byroot
byroot merged commit c839870 into ruby:master Oct 19, 2026
42 checks passed
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.

ParserError#json_path raises NoMethodError when parsing with symbolize_names: true

2 participants