Skip to content

Commit 52b37a7

Browse files
committed
fix: render unset timestamps as null in --json output
go-flashduty's Timestamp.MarshalJSON emits a quoted RFC3339 string for a set value but the bare integer 0 for the unset sentinel, so one field switches JSON type depending on record state: an active alert's end_time is the number 0 while a recovered alert's is a string. jq arithmetic over mixed-state output fails with "string and number cannot be subtracted". Add output.NullUnsetInstants, a reflection-based transform applied at the JSON marshaling boundary (JSONPrinter.Print and marshalStructured), that replaces every unset SDK timestamp with nil so it renders as null. Set values keep their concrete type and custom MarshalJSON, non-timestamp zero integers are untouched, and struct field order is preserved (verified byte-identical when no unset instant is present). TOON and table output are unchanged: they render the sentinel through String(), already always a string. The generated help note and the skill card prose that documented the old "unset stays the bare integer 0" contract are updated to match.
1 parent ae99505 commit 52b37a7

42 files changed

Lines changed: 1049 additions & 660 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/cli/root.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,14 @@ func currentOutputFormat() output.Format {
258258
}
259259

260260
// marshalStructured serializes v for machine-readable output: indented JSON for
261-
// FormatJSON (byte-compatible with the legacy --json path) and TOON via the
262-
// toon-format encoder for FormatTOON.
261+
// FormatJSON (byte-compatible with the legacy --json path, except that unset
262+
// SDK timestamps now render as null instead of the bare integer 0 — see
263+
// output.NullUnsetInstants) and TOON via the toon-format encoder for FormatTOON.
263264
func marshalStructured(v any) ([]byte, error) {
264265
if currentOutputFormat() == output.FormatTOON {
265266
return toon.Marshal(v)
266267
}
267-
return json.MarshalIndent(v, "", " ")
268+
return json.MarshalIndent(output.NullUnsetInstants(v), "", " ")
268269
}
269270

270271
// newPrinter creates a Printer based on global flags.

internal/cli/zz_generated_a2a_agents.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/cli/zz_generated_account.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)