toJSON

Returns the sheet in the same plain-object shape as toObject, for passing to JSON.stringify.

import { Sheet } from "@teakit/sheet";

Sheet.toJSON({ b: [1], a: [2] }); // { a: [2], b: [1] }  (keys ascending)

// Serialization follows native JSON rules: a row `undefined` becomes `null`.
JSON.stringify(Sheet.toJSON({ a: [1, undefined, 3] }));
// '{"a":[1,null,3]}'

API Reference

Signature

Sheet.toJSON<T, TKey extends string>(
  sheet: Sheet<T, TKey>,
): Sheet<T, TKey>;

Parameters

ParameterTypeRequiredNotes
sheetSheet<T, TKey>YesA value already known to be a sheet.

Returns

A new plain object with keys ascending and rows copied, suitable for JSON.stringify. A row undefined serializes to null per native rules.

Throws

Does not throw.

Agent Contract

FieldValue
Kindstatic conversion
Canonical nametoJSON
AliasesNone
Mutates inputsNo
ReturnsSheet<T, TKey>

Agent Notes

  • For a string, call JSON.stringify(Sheet.toJSON(sheet)); the package has no Sheet.toString / Sheet.valueOf.
  • The returned shape matches toObject.