@segmsh/json
v0.1.0
Published
JSON processor for the [segm.sh](https://segm.sh). Parses JSON files into a document (AST + segments) and stringifies them back, preserving structure while allowing content extraction.
Downloads
120
Readme
@segmsh/json
JSON processor for the segm.sh. Parses JSON files into a document (AST + segments) and stringifies them back, preserving structure while allowing content extraction.
Installation
npm install @segmsh/jsonUsage
import 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);How it works
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.
Development
npm run build
npm test