Skip to content

perf: migrate encoding/json to encoding/json/v2 - #2526

Draft
agbishop wants to merge 11 commits into
mainfrom
perf/jsonv2
Draft

agbishop wants to merge 11 commits into
mainfrom
perf/jsonv2

Conversation

@agbishop

@agbishop agbishop commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Migrates all JSON handling from encoding/json (v1) to encoding/json/v2 + encoding/json/jsontext. No GOEXPERIMENT/GODEBUG/env vars: Go 1.27 ships json/v2 by default; this changes import paths and call sites. Behaviour and wire output stay byte-identical.

What changed

  • pkgs/jsonx — the only package that still imports v1 (it owns json.DefaultOptionsV1()):
    • jsonx.V1() options passed on every Marshal/Unmarshal/stream call → identical output and v1 error text.
    • jsonx.Number / UseNumber(), SDKDecoder (for AWS SDK helpers that need a v1 *Decoder).
    • IsSyntaxError / IsTypeError / SyntaxError / TypeError: with V1 options the v2 engine still returns the v1 error types, so errors.As on jsontext.SyntacticError/json.SemanticError silently stops matching — these helpers accept both.
    • Package doc holds the full v1→v2 mapping table and gotchas (token invalidation, whitespace options belong on NewEncoder, trailing-data checks via InputOffset).
  • cmd/jsonv2mod: AST codemod used for the bulk rewrite (~4,400 files across pkgs/, internal/, services/, test/, cmd/, dashboard/, demo/); unsafe sites were reported and hand-fixed.
  • test/guards/jsonv1_import_guard_test.go: AST guard — no encoding/json import outside pkgs/jsonx (string-literal fixtures and testdata excluded).
  • Separate example modules use encoding/json/v2 directly.

Verification

  • Golden wire tests (DynamoDB, SQS, CloudWatch JSON envelopes, JSON error envelopes) written before the swap, unchanged after.
  • Race tests over every migrated package; SDK parity integration samples (DynamoDB, Kinesis, Lambda, CloudWatch, EventBridge, Glue, Athena, ECS, ECR, KMS, Firehose, Cognito, S3, SQS, SNS, SSM, Secrets Manager, Step Functions, STS, Route 53, RDS, Redshift, SES, SageMaker, Transcribe, Timestream, X-Ray) green.
  • Bugs found on the way and fixed: wfinterp test signal race (CI hang); ParseJSON trailing-garbage acceptance introduced mid-migration; Glue token-lifetime panic; application auto scaling 500-vs-400 from the error-type assumption.
  • Persistence snapshot inventory only renames json.RawMessage → jsontext.Value; persisted JSON unchanged.

bd: gopherstack-9rpwg (closed)

🤖 Generated with Claude Code

https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM

Witness Patrol and others added 3 commits November 1, 2026 10:02
…v2 swap

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
…equivalent options

Adds pkgs/jsonx (V1 option set, Number, UseNumber) and cmd/jsonv2mod, the
codemod that performs the swap mechanically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
…and single-line imports intact

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Witness Patrol and others added 5 commits November 1, 2026 12:03
…SON trailing-data check equal to Decoder.More

TestCancellationInterruptsSleep dropped its only Progress signal when the run
goroutine fired before the test reached the receive, then hung. ParseJSON used
PeekKind()!=0, which accepts trailing garbage that v1 More() rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
…ent options

Codemod plus hand fixes for streaming decoders, Indent/Compact and error
classification. jsonx gains SyntaxError/TypeError (v2 with V1 options still
returns the v1 error types) and SDKDecoder for SDK helpers taking *json.Decoder.
Snapshot inventory golden updated for json.RawMessage -> jsontext.Value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
…gosec, unconvert)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
…ncoding/json/v2; add v1-import guard

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
…nt, unused nolint)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
@agbishop

agbishop commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

📊 Code Coverage Report

Metric Value Status
Total Coverage 100.0%
0.0%
0.0%
0.0%
100.0%
75.0%
100.0%
100.0%
0.0%
86.7% ✅
New Code Coverage N/A (0/0 stmts) ✅

Tip

This project maintains a minimum coverage threshold of 85%. Maintain or improve coverage on new code to ensure long-term stability.


Last updated: Sun, 01 Nov 2026 23:30:56 GMT

Witness Patrol and others added 3 commits November 1, 2026 16:04
…CodeQL under json/v2

CodeQL sanitises v1 json.Marshal output for reflected-xss (JsonMarshalSanitizer)
and does not model v2, so OCI/ssoadmin JSON writers were flagged. Write JSON
via httputils.WriteJSONBytes (literal JSON Content-Type on a local writer plus
nosniff). Add jsonx.Number.Int and constant int32 bounds checks where
ParseInt(64) results were narrowed to int.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGWXecoauvZN2AYe1vkvgM
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.

1 participant