Add encoding.NormalizeJSON and wrapper.WithNormalizedBody(any)#11
Merged
pnguyen215 merged 10 commits intomasterfrom Mar 2, 2026
Merged
Add encoding.NormalizeJSON and wrapper.WithNormalizedBody(any)#11pnguyen215 merged 10 commits intomasterfrom
pnguyen215 merged 10 commits intomasterfrom
Conversation
Co-authored-by: pnguyen215 <39581473+pnguyen215@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Review and fix issues in w.JSON and w.JSONPretty functions
Fix w.JSON() / w.JSONPretty() double-encoding valid JSON body as escaped string
Mar 1, 2026
Co-authored-by: pnguyen215 <39581473+pnguyen215@users.noreply.github.com>
Copilot
AI
changed the title
Fix w.JSON() / w.JSONPretty() double-encoding valid JSON body as escaped string
Add encoding.NormalizeJSON and wrapper.WithNormalizedBody to fix escaped-quote JSON artifacts
Mar 1, 2026
Co-authored-by: pnguyen215 <39581473+pnguyen215@users.noreply.github.com>
Copilot
AI
changed the title
Add encoding.NormalizeJSON and wrapper.WithNormalizedBody to fix escaped-quote JSON artifacts
Add encoding.NormalizeJSON and wrapper.WithNormalizedBody(any)
Mar 1, 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.
JSON strings containing literal
\"escape artifacts (e.g. from Go raw string literals or double-encoded transports) are structurally invalid and silently breakIsJSONBody(),JSON(),JSONPretty(), andQueryJSONBody(). This adds a normalization pipeline to detect and repair such inputs before processing.encoding.NormalizeJSON(s string) (string, error)Multi-pass normalizer with early-exit validation after each pass:
0xEF 0xBB 0xBF)0x00)\"→"structural quote artifacts}/]regexpfor Pass 4; Pass 3 guards withstrings.Containsbefore allocating(*wrapper).WithNormalizedBody(v any) (*wrapper, error)Accepts any Go value and routes by type:
stringNormalizeJSONpass chain[]byteNormalizeJSONafter string conversionjson.RawMessageencoding.JSONTokenmarshalnilUsage
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.