git.iko.soy/parseable-macos
on master help sign in
Fix whole-number double serialization in JSON export to match UI display
3b58d2fiko
ParseableViewer/Models/JSONValue.swift+10−1
@@ -311,7 +311,16 @@ enum JSONValue: Codable, Hashable, Sendable, Comparable {
311 /// non-finite values serialize as `null` rather than the invalid `nan`/`inf`
311 /// non-finite values serialize as `null` rather than the invalid `nan`/`inf`
312 /// that `String(_:)` would emit.
312 /// that `String(_:)` would emit.
313 static func jsonNumber(_ v: Double) -> String {
313 static func jsonNumber(_ v: Double) -> String {
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.
314− v.isFinite ? String(v) : "null"
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)
315 }
324 }
316
325
317 // MARK: - Equatable / Hashable
326 // MARK: - Equatable / Hashable