JSON processor for the segm.sh. Parses JSON files into a document (AST + segments) and stringifies them back, preserving structure while allowing content extraction.
npm install @segmsh/jsonimport JsonProcessor from "@segmsh/json";
const processor = new JsonProcessor();
// Parse into a Document (AST + segments)
const doc = processor.parse('{"hello": "world"}');
// Modify doc.segments as needed ...
// Stringify back to JSON
const output = processor.stringify(doc);JSON is flattened into dotted keys, each value becomes a segment, and the structure is stored as a hast tree:
| JSON path | Flattened key |
|---|---|
menu.title |
menu.title |
items[0].name |
items..0.name |
items[0][1] |
items..0..1 |
.. distinguishes array indices from object keys. The original structure is fully restored on stringify.
npm run build
npm test