Fix #1474: Preserve Unicode escapes in verbose JSON output#1846
Open
kkkkwe4324 wants to merge 2 commits into
Open
Fix #1474: Preserve Unicode escapes in verbose JSON output#1846kkkkwe4324 wants to merge 2 commits into
kkkkwe4324 wants to merge 2 commits into
Conversation
added 2 commits
May 12, 2026 23:05
- Modified json.py formatter to keep \u escapes for request bodies - Added test_verbose_preserves_unicode_escape() in test_output.py - Response body remains human-readable (decoded) Before: http -v showed 'あ' instead of '\u3042' After: http -v shows '\u3042' correctly
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.
Submission Report: Fix #1474 (Preserve Escaped Unicode in Verbose Request Body)
Issue
http -vshould show escaped Unicode as-is #1474 reports that HTTPie reformats request JSON in verbose output, so escaped Unicode (for example, \u3042) is shown as the decoded character (あ). This makes verbose output inconsistent with the serialized request payload.(http -vshould show escaped Unicode as-is #1474)Key clarifications:
#814 mainly addressed the semantics and behavior explanation of :=.

#1474 is about display fidelity in verbose request output, not request semantics.
Goal: fix consistency of request JSON display in verbose mode only, without changing response formatting behavior or request semantics.
Implementation:
In [streams.py:219] inside process_body, JSON request bodies for HTTPRequest with MIME application/json are passed through directly.
This bypasses JSON reformatting for request-body display only.
Response-side pretty formatting behavior is intentionally unchanged.
Added a focused regression test to ensure verbose request output preserves \u3042.
Code locations:


Logic change: [streams.py:220]
Regression test:[test_output.py:337]
3.1 Behavior verification command
python.exe -m httpie --verbose --offline --pretty=format example.org a:=@tmp-1474.json
Conclusion: verbose request body correctly preserves escaped Unicode.
3.2 New regression test command

Result summary: Passed
3.3 Related regression test command

Result summary:Passed
Scope:
Only request-side JSON body rendering in verbose/pretty output path.
Not affected:
Request semantics (including := parsing semantics) remain unchanged.
Response JSON pretty formatting remains unchanged.
No regressions observed in related encoding test scenarios.
http -vshould show escaped Unicode as-is #1474Issue ":=" doesn't send non-ascii characters as "raw" #814 and issue
http -vshould show escaped Unicode as-is #1474 are related but not the same problem.#814 focused on the semantics of := (raw JSON field input) and whether non-ASCII content should be sent as UTF-8 bytes or escaped code points.
#1474 focuses on verbose output fidelity: whether http -v should display the request body exactly as serialized (for example, "\u3042"), instead of showing a decoded character ("あ").
In short:
#814 is about input semantics and send behavior.
#1474 is about request-body display consistency in verbose mode.
After #814, users could still observe in #1474 that verbose request output did not preserve escaped Unicode as-is, even when the serialized request body contained escape sequences. This PR addresses that specific gap.
6. Scope of This PR
This PR intentionally limits changes to request JSON body rendering in verbose/pretty output path:
Preserve escaped Unicode sequences for JSON request bodies in verbose output.
Keep response-side JSON pretty formatting behavior unchanged.
Do not alter request parsing semantics for :=.
This narrow scope minimizes regression risk while directly resolving #1474.