bug: jsonpatch does not play nice with "/" in dict keys by Copilot · Pull Request #165 · stefankoegl/python-json-patch · GitHub
Skip to content

bug: jsonpatch does not play nice with "/" in dict keys#165

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-94
Draft

bug: jsonpatch does not play nice with "/" in dict keys#165
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-94

Conversation

Copy link
Copy Markdown

Copilot AI commented May 27, 2025

Addresses the issue where / characters in dictionary keys cause unexpected JSON Patch paths (e.g. /~1fields~1test instead 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 new expand_slash_keys() utility to convert their flat dict to a nested structure before patching.

Changes Made

  • New utility function expand_slash_keys() in jsonpatch.py: converts a flat dictionary with slash-separated path-like keys into a nested dictionary, so that make_patch generates human-readable JSON Pointer paths. Raises ValueError if two keys produce conflicting paths (e.g. 'a' and 'a/b' both present).
  • Tests: Added 6 unit tests for expand_slash_keys covering simple leading-slash keys, mixed slashed/plain keys, deep nesting, no-slash passthrough, make_patch integration, and the conflict error case.
  • CI fix: Corrected --source=jsonpointer--source=jsonpatch in test.yaml, removed the unsupported Python 2.7 entry from the test matrix, and added Python 3.12.

Testing

  • ✅ All 124 tests pass (coverage run --source=jsonpatch tests.py)
  • ✅ No CodeQL security alerts

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

@stefankoegl
Copy link
Copy Markdown
Owner

Copy link
Copy Markdown
Author

Copilot AI commented Mar 20, 2026

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
Copilot AI requested a review from stefankoegl March 20, 2026 22:00
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