Repository navigation
Keep Unicode readable in CLI JSON output across serializers - #625
Open
jackwalkerlabs wants to merge 1 commit into
Open
jackwalkerlabs wants to merge 1 commit into
jackwalkerlabs wants to merge 1 commit into
Conversation
seperman
reviewed
Oct 15, 2026
seperman
left a comment
Member
There was a problem hiding this comment.
Static review: #625 Keep Unicode readable in CLI JSON output across serializers
Summary: The deep diff CLI now passes ensure_ascii=False when the stdlib json backend is used, so non-ASCII text prints as-is instead of as \uXXXX, matching what orjson already does. The library's to_json() default is unchanged. This addresses #572.
Overlap with other PRs
I found none. #612 uses ensure_ascii=False in its own new json_diff module but doesn't touch commands.py.
Security
- No code execution, file, network or dependency changes.
- Note on output: with
ensure_ascii=False, stdlib json still escapes U+0000–U+001F (including ESC),"and\. It no longer escapes DEL, C1 controls (U+0080–U+009F) or bidi/format characters such as U+202E. So such characters from the compared files can now reach the terminal unescaped on installs without orjson. The orjson backend already behaves this way, so this brings the two to parity rather than adding a new kind of issue. I mention it so the choice is deliberate.
No security concerns found in static review.
Correctness
deepdiff/commands.py:121checksdeepdiff.commands.orjson, but the backend is actually chosen fromdeepdiff.serialization.orjsoninsidejson_dumps. Both come from the same try-import, so in practice they agree. The link is implicit, though, which is why the test has to patch both modules.- Edge case: if stdout can't encode the characters (e.g.
PYTHONIOENCODING=ascii, or output redirected on Windows with a legacy code page),print()raisesUnicodeEncodeError. The fallback atcommands.py:123-124then callspprint(diff), whose repr contains the same characters, so the command would most likely end in an uncaught traceback. Before, such installs printed ASCII-escaped JSON. orjson installs already behave this way today.
Tests
test_diff_command_preserves_unicode(tests/test_command.py:15): theuse_orjson=Falsecase should fail ondev(escaped output) and pass with this change. Theuse_orjson=Truecase already passes ondevand guards parity. Both check that the output is still valid JSON. The test writes only totmp_path.
Suggestions
- Consider keeping the backend knowledge in
serialization.py, for example by lettingjson_dumpsignoreensure_asciiin the orjson branch (orjson never escapes). The CLI could then always passensure_ascii=False. - Optionally catch
UnicodeEncodeErrorand retry withensure_ascii=True, so non-UTF-8 terminals and pipes keep working.
AI-assisted static review; the code was not executed.
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.
Keep non-ASCII names and values readable in
deep diffJSON output when using the standard-library serializer, matching the existing orjson behavior. Passensure_ascii=Falseonly to the builtin backend because orjson does not accept that keyword.Fixes #572.
Validation: the new builtin-backend regression fails on the base; both backend cases pass after the change and still decode as JSON. All 27 CLI tests pass. Broader suite: 1274 passed, 44 skipped, one deselected. The excluded memory-exhaustion security test cannot set RLIMIT_AS on this macOS host (also fails on the base). Changed lines introduce no new lint errors; commands.py already has six line-length violations.
AI disclosure: Implemented, reviewed, and tested by OpenAI Codex under the account owner’s authorization; no human code review is claimed.