toJson

View as MarkdownOpen in Claude

Serialize all top-level sections to a JSON string. Internally calls toDict() and wraps the result in JSON.stringify(). Use this to persist a prompt for later restoration via PomBuilder.fromSections().

Returns

string — JSON-serialized array of section data.

Example

import { PomBuilder } from '@signalwire/sdk';
const pom = new PomBuilder();
pom.addSection('Intro', { body: 'Welcome.' });
pom.addSection('Rules', { bullets: ['Be nice.', 'Stay on topic.'] });
const json = pom.toJson();
// Persist, send over the wire, etc.
const restored = PomBuilder.fromSections(JSON.parse(json));