Repository navigation
1.10: add JSONCanonicalWriter (RFC 8785 JCS) - #95
Merged
Merged
Conversation
JSONCanonicalWriter writes JSON Canonicalization Scheme bytes: compact output, keys ordered by UTF-16 code units, short string escapes and the ECMAScript spelling of binary64 numbers. It shares the strict writer cursor and the invocation-owned work meter. NumberPolicy.preserving (default) refuses a number whose binary64 spelling would denote a different exact decimal; .rounding rounds to the nearest binary64 as RFC 8785 specifies. Scratch binary conversion text is no longer charged as output bytes on this path; existing writers are unchanged. Tests cover the RFC 8785 Appendix B vectors, the section 3.2.2 sample and the section 3.2.3 key-order example, plus policy, limits and cancellation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
First piece of the 1.10.0 "exact interchange" wave (roadmap: #94).
Design note (for API review)
\b \t \n \f \r \" \\,\u00xxfor other controls, everything else literal UTF-8; numbers in the ECMAScriptNumber::toStringspelling of their binary64 value (§3.2.2.3).JSONNumberis an exact decimal, but JCS works on binary64..preserving(default) refuses, with.conversion/.inexactConversion, any number whose canonical spelling would denote a different exact decimal.0.1and1E30pass;9007199254740993,0.10000000000000001and1e-400are refused. So canonical bytes never silently change a value..roundingfollows RFC 8785 and rounds to the nearest binary64..writingmeter (admission, sort, numbers, output). Shortest digits come from Swift's round-tripDouble.description(bounded at 32 bytes, checkpointed); the ECMAScript layout is rebuilt natively..scalarkey order and all other output. The one internal change is that binary conversion scratch text on the canonical path is not charged asoutputBytes; existing callers keep the old charge.Tests
Tests/JSONTests/CanonicalizationTests.swift, 8 functions:.preserving) and via the exact binary expansion (.rounding);.rounding;.preservingrefuses333333333.33333329);TestDiscovery.json: JSONTests 190 → 198 (native, portable, WASI). CLI identity regenerated.Local evidence
Swift 6.4.2 via swiftly, Xcode 27.2 SDK, at
0618e61's tree:python3 Scripts/ci.py --lane docs: exit 0, 4/4 commands.python3 Scripts/ci.py --lane native: exit 0, 62/62 commands. The first run failed only on the discovery count (190 vs 198), which is now updated.Not merged, tagged or released. The maintainer decides.
🤖 Generated with Claude Code