Skip to content

segmsh/json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@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/json

Usage

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

License

Apache-2.0

About

JSON processor

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors