nx-json-parser
v1.3.0
Published
Transform strings to JSON based on Markdown structure using unified/remark
Maintainers
Readme
nx-json-parser
A robust Markdown-to-JSON transformer SDK built on top of unified, remark, and remark-gfm.
Designed for structured data extraction from LLM outputs and other Markdown-formatted strings.
Features
- AST-Based Parsing: Uses
remarkfor reliable, production-grade Markdown parsing (no regex hell). - Table Support: Automatically converts Markdown tables into arrays of JavaScript objects using
remark-gfm. - List Support: Smartly handles lists, converting them to arrays.
- Bullet-Style Sections: Includes a custom plugin to detect and transform bulleted "sections" (e.g.,
- Title: Content) into structured JSON keys. - CamelCase Normalization: Automatically transforms headings and table headers into
camelCasekeys. - Extensible: Built on the
unifiedecosystem, allowing for additional plugins (math, frontmatter, etc.).
Installation
npm install nx-json-parserUsage
Basic Usage
import { markdownToJson } from 'nx-json-parser';
const md = `
# Summary
The product is a high-performance database.
## Key Features
- Scalable
- Secure
- Fast
`;
const result = markdownToJson(md);
/*
{
summary: "The product is a high-performance database.",
keyFeatures: ["Scalable", "Secure", "Fast"]
}
*/Table Support
const md = `
### Database Performance
| Metric | Value | Status |
|--------|-------|--------|
| Latency| 5ms | OK |
| Throughput | 10k ops/s | High |
`;
const result = markdownToJson(md);
/*
{
databasePerformance: [
{ metric: "Latency", value: "5ms", status: "OK" },
{ metric: "Throughput", value: "10k ops/s", status: "High" }
]
}
*/Bullet-Style Sections
LLMs often output sections using bullet points. nx-json-parser detects this pattern and treats them as structured keys:
const md = `
- Short Answer
The sky appears blue due to Rayleigh scattering.
- Technical Detail
Short-wavelength light is scattered more strongly by atmospheric gases.
`;
const result = markdownToJson(md);
/*
{
shortAnswer: "The sky appears blue due to Rayleigh scattering.",
technicalDetail: "Short-wavelength light is scattered more strongly by atmospheric gases."
}
*/API
markdownToJson(markdown: string): any
Converts a Markdown string to a JSON object.
JSONTransformer
The main class for transformation. You can provide a custom RemarkParser if needed.
import { JSONTransformer, RemarkParser } from 'nx-json-parser';
const transformer = new JSONTransformer({
parser: new RemarkParser()
});
const result = transformer.transform(md);License
ISC
