JSON processor for the localize.sh ecosystem. This package parses JSON files into a localization-friendly AST (Abstract Syntax Tree) and stringifies them back, preserving structure while allowing content extraction.
npm install @localizesh/processor-jsonimport JsonProcessor from "@localizesh/processor-json";
const processor = new JsonProcessor();
const jsonContent = '{"hello": "world"}';
// Parse into a Document (AST + Segments)
const document = processor.parse(jsonContent);
// ... modify document segments ...
// Stringify back to JSON
const newJsonContent = processor.stringify(document);This package provides a binary localize-processor-json that works with standard I/O. It reads a protobuf ParseRequest or StringifyRequest from stdin and writes a ParseResponse or StringifyResponse to stdout, making it compatible with the localize.sh plugin system.
- Flattening: Flattens JSON objects into dotted keys for clear localization context (e.g.,
menu.header.title). - Array Support: correctly handles arrays using
..notation (e.g.,items..0.name) to distinguish them from numeric object keys. - Round-trip: Ensures that parsing and then stringifying results in the original JSON structure.
npm run buildnpm test