@asymmetric-effort/jsonlint
v0.0.5
Published
A pure JavaScript/TypeScript JSON parser and validator with detailed error reporting — zero dependencies
Readme
@asymmetric-effort/jsonlint
A pure TypeScript JSON parser, linter, and validator with detailed error reporting. Zero runtime dependencies.
Feature-compatible with zaach/jsonlint.
Installation
NPM Package
npm install @asymmetric-effort/jsonlintGlobal CLI
npm install -g @asymmetric-effort/jsonlintStandalone Binary
Pre-compiled standalone binaries are produced via make build. The binary requires no runtime dependencies.
CLI Usage
jsonlint myfile.jsonOr pipe JSON via stdin:
echo '{"key": "value"}' | jsonlintOptions
| Flag | Long Form | Description | Default |
|------|-----------|-------------|---------|
| -v | --version | Print version and exit | |
| -s | --sort-keys | Sort object keys in output | false |
| -i | --in-place | Overwrite the input file with formatted output | false |
| -t CHAR | --indent CHAR | Character(s) to use for indentation | " " (2 spaces) |
| -c | --compact | Compact error display | false |
| -V FILE | --validate FILE | Validate against a JSON Schema (Draft-03) file | |
| -e ENV | --environment ENV | JSON Schema spec version | json-schema-draft-03 |
| -q | --quiet | Do not print parsed JSON to stdout | false |
| -p | --pretty-print | Force pretty printing even if invalid | false |
| -h | --help | Show help message | |
Examples
Validate and pretty-print:
jsonlint data.jsonSort keys:
jsonlint -s data.jsonFormat in place:
jsonlint -i data.jsonValidate against a schema:
jsonlint -V schema.json data.jsonCompact errors (useful for editor integrations):
jsonlint -c data.jsonModule API
import { parse } from "@asymmetric-effort/jsonlint";
// Returns parsed value or throws ParseError
const result = parse('{"key": "value"}');Advanced Usage
import { JsonParser, ParseError, LexerError } from "@asymmetric-effort/jsonlint";
const parser = new JsonParser();
// Custom error handler
parser.parseError = (message, hash) => {
console.error(`Error at line ${hash.line}: ${message}`);
throw new ParseError(message, hash);
};
try {
parser.parse(input);
} catch (e) {
if (e instanceof ParseError) {
console.error("Parse error:", e.hash);
} else if (e instanceof LexerError) {
console.error("Lexer error:", e.message);
}
}Formatter
import { formatJson } from "@asymmetric-effort/jsonlint";
// Best-effort formatting (works even on invalid JSON)
const formatted = formatJson('{"a":1,"b":2}', " ");Schema Validator
import { SchemaValidator } from "@asymmetric-effort/jsonlint";
import type { JsonSchema } from "@asymmetric-effort/jsonlint";
const schema: JsonSchema = {
type: "object",
properties: {
name: { type: "string", required: true },
age: { type: "integer", minimum: 0 },
},
};
const validator = new SchemaValidator();
const errors = validator.validate({ name: "Alice", age: 30 }, schema);
if (errors.length > 0) {
errors.forEach((e) => console.error(`${e.property}: ${e.message}`));
}Building
make setup # Install dependencies
make build # Build library and standalone binary
make test # Run all tests
make lint # Run type checker
make help # Show all targetsLicense
MIT License. Copyright (c) 2026 Asymmetric Effort, LLC.
