toJSON

Returns the string form used when serializing an Arith value with JSON.stringify.

import { Arith } from "@teakit/arith";

const value = Arith.from("0.3");

value.toJSON(); // "0.3"
JSON.stringify(value); // "\"0.3\""
JSON.stringify({ total: value }); // "{\"total\":\"0.3\"}"
JSON.stringify([Arith.from("1"), Arith.from("2")]); // "[\"1\",\"2\"]"

// Negative zero is preserved by toJSON through valueOf semantics.
Arith.from("-0").toJSON(); // "-0"

API Reference

Signature

toJSON(): string;

Parameters

ParameterTypeRequiredNotes
None--This method does not take parameters.

Returns

Returns a string.

Throws

  • Does not take user arguments; no argument validation is performed.

Agent Contract

FieldValue
Kindinstance method
Canonical nametoJSON
AliasesNone
Mutates receiverNo
Returnsstring
Accepts (string, base) overloadNo
Configuration dependenciesEXPONENTIAL_AT
Related methodsvalueOf, toString

Agent Notes

  • Import with import { Arith } from "@teakit/arith"; default imports are unsupported.
  • Use Arith.from(...) to create values. Do not generate new Arith(...) or Arith(...).
  • Use string inputs for exact decimal values, especially money-like values.
  • Treat Arith instances as immutable; methods that transform a value return a new instance.
  • Do not mutate internal fields such as c, e, s, or _isArith.