git.iko.soy/parseable-macos
on master help sign in
Fix whole-number double serialization in JSON export to match UI display
commit3b58d2f0800ca7bb6155f234b81299b7866e7f27 authoriko <mail@iko.soy> dateSun 21 Jun 2026, 15:27 (3 months ago) parent956274b
1 file changed+10−1
ParseableViewer/Models/JSONValue.swift+10−1
ParseableViewer/Models/JSONValue.swift+10−1
@@ -311,7 +311,16 @@ enum JSONValue: Codable, Hashable, Sendable, Comparable {
311311 /// non-finite values serialize as `null` rather than the invalid `nan`/`inf`
312312 /// that `String(_:)` would emit.
313313 static func jsonNumber(_ v: Double) -> String {
314− v.isFinite ? String(v) : "null"
314+ // Match `displayString`'s whole-number normalization so a value like
315+ // 100.0 serializes identically whether it's a top-level cell (which goes
316+ // through displayString) or nested in an array/object (which goes through
317+ // compactJSON). Emitting "100" instead of "100.0" is still valid JSON.
318+ guard v.isFinite else { return "null" }
319+ if v == v.rounded() && abs(v) < 1e15 {
320+ if v == 0 { return "0" } // normalize -0.0 → "0"
321+ return String(format: "%.0f", v)
322+ }
323+ return String(v)
315324 }
316325
317326 // MARK: - Equatable / Hashable