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

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