@asymmetric-effort/jsonlint 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +164 -0
- package/package.json +63 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Asymmetric Effort, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="logo.png" alt="jsonlint" width="128" height="128" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @asymmetric-effort/jsonlint
|
|
6
|
+
|
|
7
|
+
A pure TypeScript JSON parser, linter, and validator with detailed error reporting. Zero runtime dependencies.
|
|
8
|
+
|
|
9
|
+
Feature-compatible with [zaach/jsonlint](https://github.com/zaach/jsonlint).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
### NPM Package
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @asymmetric-effort/jsonlint
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Global CLI
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g @asymmetric-effort/jsonlint
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Standalone Binary
|
|
26
|
+
|
|
27
|
+
Pre-compiled standalone binaries are produced via `make build`. The binary requires no runtime dependencies.
|
|
28
|
+
|
|
29
|
+
## CLI Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
jsonlint myfile.json
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or pipe JSON via stdin:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
echo '{"key": "value"}' | jsonlint
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Options
|
|
42
|
+
|
|
43
|
+
| Flag | Long Form | Description | Default |
|
|
44
|
+
|------|-----------|-------------|---------|
|
|
45
|
+
| `-v` | `--version` | Print version and exit | |
|
|
46
|
+
| `-s` | `--sort-keys` | Sort object keys in output | `false` |
|
|
47
|
+
| `-i` | `--in-place` | Overwrite the input file with formatted output | `false` |
|
|
48
|
+
| `-t CHAR` | `--indent CHAR` | Character(s) to use for indentation | `" "` (2 spaces) |
|
|
49
|
+
| `-c` | `--compact` | Compact error display | `false` |
|
|
50
|
+
| `-V FILE` | `--validate FILE` | Validate against a JSON Schema (Draft-03) file | |
|
|
51
|
+
| `-e ENV` | `--environment ENV` | JSON Schema spec version | `json-schema-draft-03` |
|
|
52
|
+
| `-q` | `--quiet` | Do not print parsed JSON to stdout | `false` |
|
|
53
|
+
| `-p` | `--pretty-print` | Force pretty printing even if invalid | `false` |
|
|
54
|
+
| `-h` | `--help` | Show help message | |
|
|
55
|
+
|
|
56
|
+
### Examples
|
|
57
|
+
|
|
58
|
+
Validate and pretty-print:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
jsonlint data.json
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Sort keys:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
jsonlint -s data.json
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Format in place:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
jsonlint -i data.json
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Validate against a schema:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
jsonlint -V schema.json data.json
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Compact errors (useful for editor integrations):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
jsonlint -c data.json
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Module API
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { parse } from "@asymmetric-effort/jsonlint";
|
|
92
|
+
|
|
93
|
+
// Returns parsed value or throws ParseError
|
|
94
|
+
const result = parse('{"key": "value"}');
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Advanced Usage
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { JsonParser, ParseError, LexerError } from "@asymmetric-effort/jsonlint";
|
|
101
|
+
|
|
102
|
+
const parser = new JsonParser();
|
|
103
|
+
|
|
104
|
+
// Custom error handler
|
|
105
|
+
parser.parseError = (message, hash) => {
|
|
106
|
+
console.error(`Error at line ${hash.line}: ${message}`);
|
|
107
|
+
throw new ParseError(message, hash);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
parser.parse(input);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
if (e instanceof ParseError) {
|
|
114
|
+
console.error("Parse error:", e.hash);
|
|
115
|
+
} else if (e instanceof LexerError) {
|
|
116
|
+
console.error("Lexer error:", e.message);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Formatter
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { formatJson } from "@asymmetric-effort/jsonlint";
|
|
125
|
+
|
|
126
|
+
// Best-effort formatting (works even on invalid JSON)
|
|
127
|
+
const formatted = formatJson('{"a":1,"b":2}', " ");
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Schema Validator
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { SchemaValidator } from "@asymmetric-effort/jsonlint";
|
|
134
|
+
import type { JsonSchema } from "@asymmetric-effort/jsonlint";
|
|
135
|
+
|
|
136
|
+
const schema: JsonSchema = {
|
|
137
|
+
type: "object",
|
|
138
|
+
properties: {
|
|
139
|
+
name: { type: "string", required: true },
|
|
140
|
+
age: { type: "integer", minimum: 0 },
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const validator = new SchemaValidator();
|
|
145
|
+
const errors = validator.validate({ name: "Alice", age: 30 }, schema);
|
|
146
|
+
|
|
147
|
+
if (errors.length > 0) {
|
|
148
|
+
errors.forEach((e) => console.error(`${e.property}: ${e.message}`));
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Building
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
make setup # Install dependencies
|
|
156
|
+
make build # Build library and standalone binary
|
|
157
|
+
make test # Run all tests
|
|
158
|
+
make lint # Run type checker
|
|
159
|
+
make help # Show all targets
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT License. Copyright (c) 2026 Asymmetric Effort, LLC.
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@asymmetric-effort/jsonlint",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A pure JavaScript/TypeScript JSON parser and validator with detailed error reporting — zero dependencies",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "build/index.js",
|
|
7
|
+
"types": "build/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"jsonlint": "bin/jsonlint"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./build/index.js",
|
|
14
|
+
"types": "./build/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"build/",
|
|
19
|
+
"bin/",
|
|
20
|
+
"LICENSE.txt",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"clean": "make clean",
|
|
25
|
+
"lint": "make lint",
|
|
26
|
+
"test": "make test",
|
|
27
|
+
"build": "make build",
|
|
28
|
+
"typecheck": "tsc --noEmit"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/asymmetric-effort/jsonlint.git"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"json",
|
|
36
|
+
"lint",
|
|
37
|
+
"linter",
|
|
38
|
+
"parser",
|
|
39
|
+
"validator",
|
|
40
|
+
"jsonlint",
|
|
41
|
+
"zero-dependency"
|
|
42
|
+
],
|
|
43
|
+
"author": "Asymmetric Effort, LLC",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/asymmetric-effort/jsonlint/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://jsonlint.asymmetric-effort.com",
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=20.0.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
54
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
55
|
+
"bun-types": "latest",
|
|
56
|
+
"eslint": "^9.0.0",
|
|
57
|
+
"markdownlint-cli": "^0.48.0",
|
|
58
|
+
"prettier": "^3.0.0",
|
|
59
|
+
"typescript": "^5.5.0",
|
|
60
|
+
"yaml-lint": "^1.7.0"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {}
|
|
63
|
+
}
|