{{ message }}
bug: jsonpatch does not play nice with "/" in dict keys#165
Draft
bug: jsonpatch does not play nice with "/" in dict keys#165
Conversation
Owner
Co-authored-by: stefankoegl <184196+stefankoegl@users.noreply.github.com> Agent-Logs-Url: https://github.com/stefankoegl/python-json-patch/sessions/d432f792-40d4-47b2-9e6b-8697b7330028
Author
Copilot
AI
changed the title
[WIP] bug: jsonpatch does not play nice with "/" in dict keys
bug: jsonpatch does not play nice with "/" in dict keys
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Addresses the issue where
/characters in dictionary keys cause unexpected JSON Patch paths (e.g./~1fields~1testinstead of/fields/test). This is correct behavior per RFC 6901, but users who intend their slash-containing keys as path separators can now use the newexpand_slash_keys()utility to convert their flat dict to a nested structure before patching.Changes Made
expand_slash_keys()injsonpatch.py: converts a flat dictionary with slash-separated path-like keys into a nested dictionary, so thatmake_patchgenerates human-readable JSON Pointer paths. RaisesValueErrorif two keys produce conflicting paths (e.g.'a'and'a/b'both present).expand_slash_keyscovering simple leading-slash keys, mixed slashed/plain keys, deep nesting, no-slash passthrough,make_patchintegration, and the conflict error case.--source=jsonpointer→--source=jsonpatchintest.yaml, removed the unsupported Python 2.7 entry from the test matrix, and added Python 3.12.Testing
coverage run --source=jsonpatch tests.py)📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.