toJSON

Returns the canonical month string (YYYY-MM) used by JSON.stringify. A Month always serializes to a month-precision string, never an object.

import { Month } from "@teakit/month";

Month.from("2025-01").toJSON(); // "2025-01"

JSON.stringify({ month: Month.from("2025-01") }); // '{"month":"2025-01"}'
JSON.stringify([Month.from("2025-01"), Month.from("2025-02")]); // '["2025-01","2025-02"]'

API Reference

Signature

month.toJSON(): string;

Parameters

None.

Returns

Returns the canonical YYYY-MM string, regardless of any day anchor.

Agent Contract

FieldValue
Kindconversion
Canonical nametoJSON
Mutates receiverNo
Returnsstring
Precisionmonth (YYYY-MM)
Related methodstoString, toObject

Agent Notes

  • JSON.stringify of a Month yields a string, not an object; use toObject when you want a { year, month } shape.
  • toJSON always stays at month precision; the day anchor never appears.