@jsononlineparse/core
v0.1.0
Published
Fast, privacy-first JSON validation, formatting, repair and input detection utilities.
Readme
@jsononlineparse/core
Fast, lightweight, privacy-first developer utility engine for JSON validation, formatting, minification, repair, code conversion, and data classification.
Used internally by jsononlineparse.com.
Features
- Zero Dependencies: Pure TypeScript algorithm loop built for browsers and Node.js.
- Tree-Shakable: ESM modules design allowing you to import only what you need.
- Privacy First: 100% offline data processing. Payload strings never leave your machine.
- Granular Diagnostics: Normalizes V8 parsing errors into structured metadata with lines, columns, and explanations.
Installation
npm install @jsononlineparse/coreQuick Start
import { validateJSON, formatJSON, repairJSON, detectInput } from "@jsononlineparse/core"
// 1. Syntax Validation
const validation = validateJSON('{"name":"Salil"}')
if (validation.valid) {
console.log("Valid JSON value:", validation.value)
} else {
console.error("Syntax code:", validation.error.code) // e.g. "TRAILING_COMMA"
}
// 2. Intelligent Format
const format = formatJSON('{"id":123}', { indent: 2 })
if (format.success) {
console.log(format.value)
}
// 3. Smart Repair (unquoted keys, single quotes, trailing commas)
const repair = repairJSON("{name: 'Salil', age: 30,}")
if (repair.success) {
console.log("Repaired:", repair.value) // {"name":"Salil","age":30}
console.log("Applied Repairs:", repair.repairs)
}API Reference
validateJSON(input: string): ValidationResult
Returns { valid: true, value: any } or { valid: false, error: JOPError }.
formatJSON(input: string, options?: FormatOptions): Result<string>
Reformats JSON text. Options let you configure space indentation (number | 'tab').
minifyJSON(input: string): Result<string>
Strips all whitespaces, newlines, and indentation from valid JSON documents.
repairJSON(input: string): RepairResult
Resolves common JSON mistakes and logs list of actions taken.
diagnoseJSONError(input: string): DiagnoseResult
Analyzes syntactical exceptions with lines, columns, explanations, and instructions.
detectInput(input: string): DetectionResult
Analyzes character blocks to identify if content is JSON, JWT, API errors, or plain logs.
jsonToTypeScript(input: string, rootName?: string): Result<string>
Translates JSON structures into structured TypeScript interfaces and type declarations.
Privacy & Security
This library contains no network logic, telemetry scripts, or external dependencies. All data is processed synchronously on the local thread.
License
MIT
