@isdk/json-repair 0.1.2 → 0.2.0
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/README.cn.md +245 -14
- package/README.md +293 -14
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +777 -23
- package/dist/index.d.ts +777 -23
- package/dist/index.js +1 -1
- package/docs/README.md +293 -14
- package/docs/_media/README.cn.md +245 -14
- package/docs/classes/RepairParser.md +71 -5
- package/docs/classes/SchemaWalker.md +126 -6
- package/docs/functions/compareScores.md +32 -0
- package/docs/functions/discardedText.md +42 -0
- package/docs/functions/expectsArrayRoot.md +23 -0
- package/docs/functions/findImplicitRecordRegion.md +32 -0
- package/docs/functions/jsonRepair.md +4 -3
- package/docs/functions/jsonRepairResult.md +50 -0
- package/docs/functions/locateJsonCandidates.md +33 -0
- package/docs/functions/looksLikeSchemaEcho.md +29 -0
- package/docs/functions/renderValidatorErrors.md +32 -0
- package/docs/functions/scoreCandidate.md +45 -0
- package/docs/functions/validateValue.md +38 -0
- package/docs/globals.md +19 -0
- package/docs/interfaces/CandidateScore.md +63 -0
- package/docs/interfaces/JsonCandidate.md +71 -0
- package/docs/interfaces/LocatedJson.md +48 -0
- package/docs/interfaces/RepairOptions.md +257 -19
- package/docs/interfaces/RepairResult.md +58 -0
- package/docs/interfaces/ValidationError.md +27 -0
- package/docs/type-aliases/CommentStyle.md +13 -0
- package/docs/type-aliases/EscapeMode.md +13 -0
- package/docs/type-aliases/JSONPath.md +1 -1
- package/docs/type-aliases/LiteralDialect.md +13 -0
- package/docs/type-aliases/RepairFlag.md +11 -0
- package/package.json +38 -12
- package/.prettierignore +0 -4
- package/.prettierrc +0 -8
- package/.versionrc +0 -36
- package/CHANGELOG.md +0 -18
- package/TODO +0 -0
- package/eslint.config.mjs +0 -31
- package/setupVitest.mjs +0 -15
- package/tsconfig.json +0 -19
- package/tsconfig.spec.json +0 -19
- package/tsup.config.ts +0 -34
- package/typedoc.config.cjs +0 -7
- package/vite.config.mjs +0 -16
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Interface: RepairOptions
|
|
8
8
|
|
|
9
|
-
Defined in: [types.ts:4](https://github.com/isdk/json-repair.js/blob/
|
|
9
|
+
Defined in: [types.ts:4](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L4)
|
|
10
10
|
|
|
11
11
|
Options for the JSON repair process.
|
|
12
12
|
|
|
@@ -14,50 +14,288 @@ Options for the JSON repair process.
|
|
|
14
14
|
|
|
15
15
|
### additionalProperties?
|
|
16
16
|
|
|
17
|
-
> `optional` **additionalProperties
|
|
17
|
+
> `optional` **additionalProperties?**: `"keep"` \| `"remove"`
|
|
18
18
|
|
|
19
|
-
Defined in: [types.ts:
|
|
19
|
+
Defined in: [types.ts:76](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L76)
|
|
20
20
|
|
|
21
21
|
Defines how to handle properties not defined in the Schema.
|
|
22
22
|
|
|
23
23
|
- `'keep'` (default): Keeps these extra properties in the output.
|
|
24
|
-
- `'remove'`:
|
|
24
|
+
- `'remove'`: Drops them. Only applies at a level whose Schema declares `properties`;
|
|
25
|
+
a free-form level has no "extra" keys and is left untouched.
|
|
26
|
+
|
|
27
|
+
This option is independent from the JSON Schema keyword `additionalProperties: false`,
|
|
28
|
+
which is respected on its own when validating incoming keys.
|
|
25
29
|
|
|
26
30
|
***
|
|
27
31
|
|
|
28
32
|
### coerceTypes?
|
|
29
33
|
|
|
30
|
-
> `optional` **coerceTypes
|
|
34
|
+
> `optional` **coerceTypes?**: `boolean`
|
|
35
|
+
|
|
36
|
+
Defined in: [types.ts:64](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L64)
|
|
37
|
+
|
|
38
|
+
Whether to coerce values to the type the Schema declares. Enabled by default.
|
|
39
|
+
|
|
40
|
+
- `true` (default): `"Approx. 1,200.50 USD"` becomes `1200.5`, `"yes"` becomes `true`,
|
|
41
|
+
`"Processing!"` becomes the enum entry it fuzzy matches, `12` becomes `"12"` when the
|
|
42
|
+
Schema says `type: 'string'`.
|
|
43
|
+
- `false`: values are returned exactly as they were parsed.
|
|
44
|
+
|
|
45
|
+
Coercion needs the Schema of the property the value belongs to; a level that declares
|
|
46
|
+
no types is left alone.
|
|
47
|
+
|
|
48
|
+
Coercing to a declared `string` reuses the text the document wrote, not the number it
|
|
49
|
+
parsed to, so a leading zero survives: `{ id: 01234 }` becomes `"01234"`.
|
|
50
|
+
`null` and structures (`{}` / `[]`) are never stringified - `"null"` and
|
|
51
|
+
`"[object Object]"` are not what a `type: 'string'` declaration asks for.
|
|
52
|
+
|
|
53
|
+
A coercion that keeps part of a value and gives up the text around it says so:
|
|
54
|
+
`coerced-text-dropped`. A unit given up that way (`Approx. USD`) is the option doing its
|
|
55
|
+
job; text long enough to read as a sentence is listed in [RepairResult.discarded](RepairResult.md#discarded)
|
|
56
|
+
too, because greedy capture can run a value into prose the model wrote after it
|
|
57
|
+
(`age: 30\n\nHope this helps!}` -> `30`) and the sentence would otherwise leave no trace.
|
|
58
|
+
|
|
59
|
+
***
|
|
60
|
+
|
|
61
|
+
### comments?
|
|
62
|
+
|
|
63
|
+
> `optional` **comments?**: `boolean` \| [`CommentStyle`](../type-aliases/CommentStyle.md)[]
|
|
64
|
+
|
|
65
|
+
Defined in: [types.ts:115](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L115)
|
|
66
|
+
|
|
67
|
+
Which comment styles are skipped, and only where a member is expected: between two
|
|
68
|
+
fields, after `{` or `[`, before a closing bracket, and after a completed value.
|
|
69
|
+
|
|
70
|
+
Strict JSON has no comments, so this is off by default - skipping one consumes
|
|
71
|
+
characters, and only the caller knows which style its models write. Open the style you
|
|
72
|
+
actually see.
|
|
73
|
+
|
|
74
|
+
- `'line'` - `//` to the end of the line (JSONC, and most JavaScript-trained models).
|
|
75
|
+
- `'block'` - `/* ... */`, and only when it is closed: an unterminated `/*` stays text.
|
|
76
|
+
- `'hash'` - `#` to the end of the line (Python-trained models).
|
|
77
|
+
- `true` - all three. `false` or `[]` - none, which is the default.
|
|
78
|
+
|
|
79
|
+
A style is never recognised inside a string or inside a bare token, so
|
|
80
|
+
`url: https://x.com/a`, `issue: #123` and `"#ff0000"` survive every setting. With the
|
|
81
|
+
default, a comment written between two fields ends up inside one of them; turning the
|
|
82
|
+
switch on is what prevents that. Emits `comment-skipped`.
|
|
83
|
+
|
|
84
|
+
***
|
|
85
|
+
|
|
86
|
+
### dangling?
|
|
87
|
+
|
|
88
|
+
> `optional` **dangling?**: `boolean`
|
|
31
89
|
|
|
32
|
-
Defined in: [types.ts:
|
|
90
|
+
Defined in: [types.ts:175](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L175)
|
|
33
91
|
|
|
34
|
-
Whether
|
|
92
|
+
Whether a key or separator the output was cut off at is dropped or kept.
|
|
35
93
|
|
|
36
|
-
|
|
94
|
+
`{"a": 1, "b`: `true` (default) gives `{ a: 1 }`. `false` gives `{ a: '1, "b' }` - the
|
|
95
|
+
fragment written into a field that was already correct, which is exactly what this option
|
|
96
|
+
exists to prevent. Dropping is the default, and the dropped text is listed in
|
|
97
|
+
[RepairResult.discarded](RepairResult.md#discarded) and flagged `dangling-dropped`, so nothing disappears
|
|
98
|
+
without a trace. Only the fragment is dropped: the container closes and a record written
|
|
99
|
+
after it is still read, so `{"a": 1, "b"} {"c": 2}` becomes `[{ a: 1 }, { c: 2 }]`. A
|
|
100
|
+
broken key with a value after it is syntax to repair, not a fragment, and is left alone.
|
|
101
|
+
|
|
102
|
+
***
|
|
103
|
+
|
|
104
|
+
### escapes?
|
|
105
|
+
|
|
106
|
+
> `optional` **escapes?**: [`EscapeMode`](../type-aliases/EscapeMode.md)
|
|
107
|
+
|
|
108
|
+
Defined in: [types.ts:162](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L162)
|
|
109
|
+
|
|
110
|
+
How much the parser trusts the backslashes a document writes.
|
|
111
|
+
|
|
112
|
+
The three settings read as one axis - how far the document's escapes are escapes:
|
|
113
|
+
|
|
114
|
+
- `'json5'` (default): JSON's own escapes decode, the JSON5-style `\xNN` decodes to the
|
|
115
|
+
character it names, and an escape of a character that needs none is unwrapped
|
|
116
|
+
(`"\$10"` -> `$10`, `"C:\Users"` -> `C:Users`) the way JSON5 reads one.
|
|
117
|
+
- `'json'`: only the escapes JSON defines decode. Anything else stays exactly as the
|
|
118
|
+
document wrote it, backslash included (`"C:\Users"` -> `C:\Users`), so markdown and
|
|
119
|
+
LaTeX punctuation keeps its backslashes and a path keeps its separators.
|
|
120
|
+
- `'raw'`: nothing decodes - a backslash is content. `"C:\temp"` is a path, not a tab,
|
|
121
|
+
and `"\frac{a}{b}"` is a LaTeX command, not a form feed. The setting is honest about
|
|
122
|
+
what it costs: it applies to escapes JSON defines too, so `"a\nb"` stays two characters
|
|
123
|
+
and a value can no longer carry a newline. Use it when the values are paths, regular
|
|
124
|
+
expressions or markup rather than prose.
|
|
125
|
+
|
|
126
|
+
A backslash is structural in every setting: it always keeps the character behind it inside
|
|
127
|
+
the string, so a value is never cut where the model escaped something. An incomplete hex
|
|
128
|
+
escape (`\xg`, `\uZZ`) decodes nothing in every setting and stays as written.
|
|
129
|
+
Whichever is chosen, an escape strict JSON would reject is reported as `invalid-escape`.
|
|
37
130
|
|
|
38
131
|
***
|
|
39
132
|
|
|
40
133
|
### keyMatching?
|
|
41
134
|
|
|
42
|
-
> `optional` **keyMatching
|
|
135
|
+
> `optional` **keyMatching?**: `boolean` \| ((`key`, `properties`) => `string` \| `undefined`)
|
|
136
|
+
|
|
137
|
+
Defined in: [types.ts:21](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L21)
|
|
138
|
+
|
|
139
|
+
Fuzzy matching of property keys against the Schema's declared `properties`.
|
|
140
|
+
|
|
141
|
+
- `false` (default): Only an exactly declared key counts as a match.
|
|
142
|
+
- `true`: Case-insensitive and separator-insensitive matching, so `user_name`,
|
|
143
|
+
`userName`, `USER-NAME` and `user name` all resolve to the declared key.
|
|
144
|
+
- `(key: string, properties: string[]) => string | undefined`: Custom mapping logic;
|
|
145
|
+
it receives the incoming key and the declared names, and returns the name to use
|
|
146
|
+
(or `undefined` to fall back to the incoming key).
|
|
147
|
+
|
|
148
|
+
A match renames the key to the Schema's name in the output and makes nested Schema
|
|
149
|
+
lookups (and therefore type coercion) work for it.
|
|
150
|
+
It also decides where greedy capture stops: with `true` a separator or case variant of a
|
|
151
|
+
declared key (`user_name:` for `userName`) ends the value in front of it.
|
|
152
|
+
When you reuse a `SchemaWalker`, pass this option to `SchemaWalker.create()`.
|
|
153
|
+
|
|
154
|
+
***
|
|
155
|
+
|
|
156
|
+
### literals?
|
|
157
|
+
|
|
158
|
+
> `optional` **literals?**: `boolean` \| [`LiteralDialect`](../type-aliases/LiteralDialect.md)[]
|
|
159
|
+
|
|
160
|
+
Defined in: [types.ts:138](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L138)
|
|
161
|
+
|
|
162
|
+
Which bare tokens (tokens with no quotes around them) are read as a literal of another
|
|
163
|
+
language.
|
|
43
164
|
|
|
44
|
-
|
|
165
|
+
`ok: True` means `true`, not the word `True`: the token carries no quotes, so it is not a
|
|
166
|
+
string in any JSON dialect either - reading it as a literal is reading the model, while
|
|
167
|
+
turning it into `'True'` invents a value.
|
|
45
168
|
|
|
46
|
-
|
|
169
|
+
- `'python'` - `True` -> `true`, `False` -> `false`, `None` -> `null`.
|
|
170
|
+
- `'js'` - `undefined` -> `null`. `NaN` is left as the text it spells: no JSON number
|
|
171
|
+
can carry it, so the reported errors point at the field instead of the parser inventing
|
|
172
|
+
a value that cannot be serialised.
|
|
173
|
+
- `true` - both dialects, which is the default. `false` or `[]` - neither: the token
|
|
174
|
+
becomes the string it spells.
|
|
47
175
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
176
|
+
A model trained on JavaScript does not write `None` and a Python-trained one rarely writes
|
|
177
|
+
`undefined`, so the list is how you say which of them can occur. It never applies to a
|
|
178
|
+
quoted `"True"` (always a string), never to a key, and never to a path whose Schema names
|
|
179
|
+
a type - there [coerceTypes](#coercetypes) decides, and it already reads `True` as `true`.
|
|
180
|
+
Emits `non-json-literal`.
|
|
181
|
+
|
|
182
|
+
***
|
|
183
|
+
|
|
184
|
+
### locate?
|
|
185
|
+
|
|
186
|
+
> `optional` **locate?**: `boolean`
|
|
187
|
+
|
|
188
|
+
Defined in: [types.ts:201](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L201)
|
|
189
|
+
|
|
190
|
+
Whether to look for the JSON inside the input text first.
|
|
191
|
+
|
|
192
|
+
LLM output is text, not a document: the JSON often sits inside a Markdown fence and
|
|
193
|
+
between sentences. With `true` (the default) the input is scanned for
|
|
194
|
+
quote-aware, escape-aware, bracket-balanced JSON regions and the best one is repaired;
|
|
195
|
+
prose and fences around it are dropped and reported. With `false` the whole string is
|
|
196
|
+
parsed as if it were already a JSON document (the behaviour up to 0.1.x).
|
|
197
|
+
|
|
198
|
+
Input that already parses as JSON is never touched either way.
|
|
199
|
+
|
|
200
|
+
***
|
|
201
|
+
|
|
202
|
+
### onDiscard?
|
|
203
|
+
|
|
204
|
+
> `optional` **onDiscard?**: `"throw"` \| `"report"` \| `"ignore"`
|
|
205
|
+
|
|
206
|
+
Defined in: [types.ts:230](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L230)
|
|
207
|
+
|
|
208
|
+
What to do with text the repair dropped on the floor (prose, fences, losing fragments).
|
|
209
|
+
|
|
210
|
+
- `'report'` (default): drop it, but list it in `RepairResult.discarded`.
|
|
211
|
+
- `'throw'`: refuse the input - a caller that cannot afford to lose content should not
|
|
212
|
+
accept a repair that discards any.
|
|
213
|
+
- `'ignore'`: drop it silently.
|
|
214
|
+
|
|
215
|
+
***
|
|
216
|
+
|
|
217
|
+
### onMultiple?
|
|
218
|
+
|
|
219
|
+
> `optional` **onMultiple?**: `"best"` \| `"last"` \| `"first"` \| `"throw"`
|
|
220
|
+
|
|
221
|
+
Defined in: [types.ts:220](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L220)
|
|
222
|
+
|
|
223
|
+
How to choose when the input contains more than one JSON fragment.
|
|
224
|
+
|
|
225
|
+
- `'best'` (default): rank the fragments by how well they fit the Schema - fewer
|
|
226
|
+
validation errors, more `required` fields carrying real values, more declared fields,
|
|
227
|
+
fewer Schema keywords in the answer - and take the winner. A tie is decided by position,
|
|
228
|
+
last first, because a model usually drafts before it answers; the tie is then reported as
|
|
229
|
+
`ambiguous-candidates` rather than hidden. An extra key the Schema never named is not held
|
|
230
|
+
against a fragment ([CandidateScore.undeclaredKeys](CandidateScore.md#undeclaredkeys) reports it); only an answer built
|
|
231
|
+
out of the Schema itself is.
|
|
232
|
+
- `'last'` / `'first'`: take the position regardless of how well the fragment fits. The
|
|
233
|
+
Schema errors of the chosen fragment are still reported.
|
|
234
|
+
- `'throw'`: reject the input outright and list the candidates with their scores.
|
|
235
|
+
|
|
236
|
+
Without a Schema the ranking has no information to work with, so it collapses to the
|
|
237
|
+
position rule (the last fragment).
|
|
51
238
|
|
|
52
239
|
***
|
|
53
240
|
|
|
54
241
|
### stringCaptureStrategy?
|
|
55
242
|
|
|
56
|
-
> `optional` **stringCaptureStrategy
|
|
243
|
+
> `optional` **stringCaptureStrategy?**: `"conservative"` \| `"aggressive"`
|
|
244
|
+
|
|
245
|
+
Defined in: [types.ts:40](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L40)
|
|
246
|
+
|
|
247
|
+
Strategy for greedy string capture when the strict JSON path failed for a value.
|
|
248
|
+
|
|
249
|
+
- `'aggressive'` (default): When the Schema declares property names for the current
|
|
250
|
+
level, the captured value only ends at one of those declared keys. Text that merely
|
|
251
|
+
looks like `"some words":` stays inside the value.
|
|
252
|
+
- `'conservative'`: Any text matching the `"key":` / `key:` pattern ends the value,
|
|
253
|
+
which keeps the structure of the document at the cost of cutting values short.
|
|
254
|
+
|
|
255
|
+
A whitespace-containing key the Schema declares is a breakpoint in both strategies even
|
|
256
|
+
when the document left it unquoted (`{ Capital: Berlin, Official language: Italian }`),
|
|
257
|
+
because it can only be recognised from the declaration.
|
|
258
|
+
Neither strategy affects values that were parsed by the strict JSON path; the
|
|
259
|
+
boundary rules described in the README apply to those unchanged.
|
|
260
|
+
|
|
261
|
+
***
|
|
262
|
+
|
|
263
|
+
### unescapedQuotes?
|
|
264
|
+
|
|
265
|
+
> `optional` **unescapedQuotes?**: `"keep"` \| `"declared"` \| `"lookahead"`
|
|
266
|
+
|
|
267
|
+
Defined in: [types.ts:95](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L95)
|
|
268
|
+
|
|
269
|
+
Where a quoted value ends when the model left one of its quotes unescaped -
|
|
270
|
+
`{"t": "The "Best" Paper", "y": 2020}`.
|
|
271
|
+
|
|
272
|
+
- `'keep'` (default) - what the document spells, delimiters included:
|
|
273
|
+
`t = '"The "Best" Paper"'`. Nothing is inferred, which is the rule the README section
|
|
274
|
+
"How Property Boundaries Are Detected" describes.
|
|
275
|
+
- `'declared'` - the first quote after which a member the Schema declares begins:
|
|
276
|
+
`t = 'The "Best" Paper'`. The Schema named that member, so the boundary is known rather
|
|
277
|
+
than guessed - and where the Schema names nothing at that level, nothing is inferred
|
|
278
|
+
either.
|
|
279
|
+
- `'lookahead'` - the same rule judged by the shape of the text alone, for documents with
|
|
280
|
+
no Schema. It reads more, and guesses more.
|
|
281
|
+
|
|
282
|
+
A document that `JSON.parse` accepts is never affected: the strict parse is tried first,
|
|
283
|
+
and only a quoted value it could not close comes here. Emits `unescaped-quote-inferred`.
|
|
284
|
+
|
|
285
|
+
***
|
|
286
|
+
|
|
287
|
+
### wrapArrays?
|
|
288
|
+
|
|
289
|
+
> `optional` **wrapArrays?**: `boolean`
|
|
57
290
|
|
|
58
|
-
Defined in: [types.ts:
|
|
291
|
+
Defined in: [types.ts:188](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L188)
|
|
59
292
|
|
|
60
|
-
|
|
293
|
+
Whether a record the Schema expects inside a list is read as one item: a single object
|
|
294
|
+
under a root `array` becomes `[object]`, and sibling records written side by side
|
|
295
|
+
(`{...} {...}`, or the same without braces) become the items of that list.
|
|
61
296
|
|
|
62
|
-
-
|
|
63
|
-
|
|
297
|
+
Enabled by default - the structure was declared by the Schema, so it is not a guess.
|
|
298
|
+
Set it to `false` to keep the value exactly as the document wrote it and let the
|
|
299
|
+
reported `errors` say what is missing. The cost: the record is no longer looked up
|
|
300
|
+
against `items`, so its own keys lose their Schema guide - coercion stops applying and
|
|
301
|
+
a value can run into the next key. That is why the default is `true`.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[**@isdk/json-repair**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/json-repair](../globals.md) / RepairResult
|
|
6
|
+
|
|
7
|
+
# Interface: RepairResult\<T\>
|
|
8
|
+
|
|
9
|
+
Defined in: [types.ts:365](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L365)
|
|
10
|
+
|
|
11
|
+
Everything a repair produced: the value, what was noticed about the input, what still
|
|
12
|
+
fails against the Schema, and what was discarded to get there.
|
|
13
|
+
|
|
14
|
+
## Type Parameters
|
|
15
|
+
|
|
16
|
+
### T
|
|
17
|
+
|
|
18
|
+
`T` = `any`
|
|
19
|
+
|
|
20
|
+
## Properties
|
|
21
|
+
|
|
22
|
+
### candidates
|
|
23
|
+
|
|
24
|
+
> **candidates**: [`JsonCandidate`](JsonCandidate.md)[]
|
|
25
|
+
|
|
26
|
+
Defined in: [types.ts:369](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L369)
|
|
27
|
+
|
|
28
|
+
***
|
|
29
|
+
|
|
30
|
+
### discarded
|
|
31
|
+
|
|
32
|
+
> **discarded**: `string`[]
|
|
33
|
+
|
|
34
|
+
Defined in: [types.ts:370](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L370)
|
|
35
|
+
|
|
36
|
+
***
|
|
37
|
+
|
|
38
|
+
### errors
|
|
39
|
+
|
|
40
|
+
> **errors**: [`ValidationError`](ValidationError.md)[]
|
|
41
|
+
|
|
42
|
+
Defined in: [types.ts:368](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L368)
|
|
43
|
+
|
|
44
|
+
***
|
|
45
|
+
|
|
46
|
+
### flags
|
|
47
|
+
|
|
48
|
+
> **flags**: [`RepairFlag`](../type-aliases/RepairFlag.md)[]
|
|
49
|
+
|
|
50
|
+
Defined in: [types.ts:367](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L367)
|
|
51
|
+
|
|
52
|
+
***
|
|
53
|
+
|
|
54
|
+
### value
|
|
55
|
+
|
|
56
|
+
> **value**: `T`
|
|
57
|
+
|
|
58
|
+
Defined in: [types.ts:366](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L366)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[**@isdk/json-repair**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/json-repair](../globals.md) / ValidationError
|
|
6
|
+
|
|
7
|
+
# Interface: ValidationError
|
|
8
|
+
|
|
9
|
+
Defined in: [types.ts:356](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L356)
|
|
10
|
+
|
|
11
|
+
A JSON Schema violation, located by path so it can be handed back to a model verbatim.
|
|
12
|
+
|
|
13
|
+
## Properties
|
|
14
|
+
|
|
15
|
+
### message
|
|
16
|
+
|
|
17
|
+
> **message**: `string`
|
|
18
|
+
|
|
19
|
+
Defined in: [types.ts:358](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L358)
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### path
|
|
24
|
+
|
|
25
|
+
> **path**: [`JSONPath`](../type-aliases/JSONPath.md)
|
|
26
|
+
|
|
27
|
+
Defined in: [types.ts:357](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L357)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[**@isdk/json-repair**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/json-repair](../globals.md) / CommentStyle
|
|
6
|
+
|
|
7
|
+
# Type Alias: CommentStyle
|
|
8
|
+
|
|
9
|
+
> **CommentStyle** = `"line"` \| `"block"` \| `"hash"`
|
|
10
|
+
|
|
11
|
+
Defined in: [types.ts:257](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L257)
|
|
12
|
+
|
|
13
|
+
A comment style. See [RepairOptions.comments](../interfaces/RepairOptions.md#comments).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[**@isdk/json-repair**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/json-repair](../globals.md) / EscapeMode
|
|
6
|
+
|
|
7
|
+
# Type Alias: EscapeMode
|
|
8
|
+
|
|
9
|
+
> **EscapeMode** = `"json5"` \| `"json"` \| `"raw"`
|
|
10
|
+
|
|
11
|
+
Defined in: [types.ts:263](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L263)
|
|
12
|
+
|
|
13
|
+
How much a backslash is trusted as an escape. See [RepairOptions.escapes](../interfaces/RepairOptions.md#escapes).
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
> **JSONPath** = (`string` \| `number`)[]
|
|
10
10
|
|
|
11
|
-
Defined in: [types.ts:
|
|
11
|
+
Defined in: [types.ts:237](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L237)
|
|
12
12
|
|
|
13
13
|
Represents the current path in a JSON structure.
|
|
14
14
|
A list of strings (keys) and numbers (indices).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[**@isdk/json-repair**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/json-repair](../globals.md) / LiteralDialect
|
|
6
|
+
|
|
7
|
+
# Type Alias: LiteralDialect
|
|
8
|
+
|
|
9
|
+
> **LiteralDialect** = `"js"` \| `"python"`
|
|
10
|
+
|
|
11
|
+
Defined in: [types.ts:260](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L260)
|
|
12
|
+
|
|
13
|
+
A language whose bare-token literals a model may write. See [RepairOptions.literals](../interfaces/RepairOptions.md#literals).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[**@isdk/json-repair**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/json-repair](../globals.md) / RepairFlag
|
|
6
|
+
|
|
7
|
+
# Type Alias: RepairFlag
|
|
8
|
+
|
|
9
|
+
> **RepairFlag** = `"markdown-fence"` \| `"prose-prefix"` \| `"trailing-chatter"` \| `"implicit-structure"` \| `"truncated-candidate"` \| `"sibling-objects-merged"` \| `"extra-fragments-dropped"` \| `"duplicate-candidates"` \| `"ambiguous-candidates"` \| `"empty-required"` \| `"schema-echo-detected"` \| `"unescaped-quote-inferred"` \| `"comment-skipped"` \| `"comment-in-value"` \| `"non-json-literal"` \| `"invalid-escape"` \| `"dangling-dropped"` \| `"unparsed-tail"` \| `"coerced-text-dropped"` \| `"nesting-limited"`
|
|
10
|
+
|
|
11
|
+
Defined in: [types.ts:265](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/types.ts#L265)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isdk/json-repair",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A powerful, schema-guided JSON repair library for fixing broken JSON generated by LLMs, featuring semantic coercion and fuzzy matching.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json",
|
|
@@ -18,20 +18,35 @@
|
|
|
18
18
|
],
|
|
19
19
|
"author": "Riceball LEE <snowyu.lee@gmail.com>",
|
|
20
20
|
"homepage": "https://github.com/isdk/json-repair.js",
|
|
21
|
-
"repository":
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/isdk/json-repair.js"
|
|
24
|
+
},
|
|
22
25
|
"bugs": "https://github.com/@isdk/json-repair.js/issues",
|
|
23
26
|
"license": "MIT",
|
|
24
|
-
"main": "dist/index.js",
|
|
25
|
-
"types": "dist/index.d.ts",
|
|
26
27
|
"type": "module",
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
27
31
|
"exports": {
|
|
28
|
-
".":
|
|
32
|
+
".": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/index.d.cts",
|
|
39
|
+
"default": "./dist/index.cjs"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
29
43
|
},
|
|
30
44
|
"dependencies": {
|
|
31
45
|
"@apidevtools/json-schema-ref-parser": "^15.1.3",
|
|
32
46
|
"lodash-es": "^4.17.23"
|
|
33
47
|
},
|
|
34
48
|
"devDependencies": {
|
|
49
|
+
"@antfu/eslint-config": "^4.19.0",
|
|
35
50
|
"@types/json-schema": "^7.0.15",
|
|
36
51
|
"@types/lodash-es": "^4.17.12",
|
|
37
52
|
"@types/node": "^25.1.0",
|
|
@@ -39,30 +54,41 @@
|
|
|
39
54
|
"eslint-config-prettier": "^10.1.8",
|
|
40
55
|
"eslint-plugin-tsdoc": "^0.5.0",
|
|
41
56
|
"prettier": "^3.8.1",
|
|
57
|
+
"prettier-plugin-markdown-table-layout": "^0.2.1",
|
|
42
58
|
"terser": "^5.46.0",
|
|
43
59
|
"tsup": "^8.5.1",
|
|
44
60
|
"tsx": "^4.21.0",
|
|
45
|
-
"typedoc": "^0.28.
|
|
46
|
-
"typedoc-plugin-markdown": "^4.
|
|
61
|
+
"typedoc": "^0.28.20",
|
|
62
|
+
"typedoc-plugin-markdown": "^4.13.1",
|
|
47
63
|
"typescript": "~5.7.3",
|
|
48
64
|
"vite": "^7.3.1",
|
|
49
65
|
"vite-tsconfig-paths": "^6.0.5",
|
|
50
66
|
"vitest": "^4.0.18"
|
|
51
67
|
},
|
|
68
|
+
"files": [
|
|
69
|
+
"dist",
|
|
70
|
+
"docs",
|
|
71
|
+
"README.cn.md",
|
|
72
|
+
"LICENSE-MIT"
|
|
73
|
+
],
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=20.19"
|
|
76
|
+
},
|
|
77
|
+
"sideEffects": false,
|
|
52
78
|
"scripts": {
|
|
53
79
|
"build-fast": "tsup",
|
|
54
80
|
"build": "pnpm run build-fast --dts-resolve --dts && pnpm run doc:md",
|
|
55
81
|
"clean": "rm -fr web docs dist",
|
|
56
82
|
"doc": "typedoc --plugin none --out web",
|
|
57
83
|
"doc:md": "typedoc --plugin typedoc-plugin-markdown --out docs",
|
|
58
|
-
"format": "
|
|
59
|
-
"format:
|
|
60
|
-
"format:fix": "pnpm run format:base --write",
|
|
84
|
+
"format": "prettier --check \"**/*.{md,json,jsonc,yaml,yml,ts,mjs,cjs}\"",
|
|
85
|
+
"format:fix": "prettier --write \"**/*.{md,json,jsonc,yaml,yml,ts,mjs,cjs}\"",
|
|
61
86
|
"lint": "eslint .",
|
|
62
87
|
"lint:fix": "pnpm run lint --fix",
|
|
63
|
-
"style": "pnpm run format
|
|
64
|
-
"style:fix": "pnpm run format:fix &&
|
|
88
|
+
"style": "pnpm run format && pnpm run lint",
|
|
89
|
+
"style:fix": "pnpm run format:fix && pnpm run lint:fix",
|
|
65
90
|
"test": "vitest run",
|
|
91
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
66
92
|
"release": "pnpm run clean && pnpm run build && git add -f docs && git ci -m 'docs: update API docs' && pnpm dlx commit-and-tag-version -s",
|
|
67
93
|
"release.alpha": "pnpm run release -- --prerelease alpha"
|
|
68
94
|
}
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/.versionrc
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"types": [
|
|
3
|
-
{
|
|
4
|
-
"type": "feat",
|
|
5
|
-
"section": "Features"
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
"type": "fix",
|
|
9
|
-
"section": "Bug Fixes"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"type": "chore",
|
|
13
|
-
"hidden": true
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"type": "docs",
|
|
17
|
-
"hidden": true
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"type": "style",
|
|
21
|
-
"hidden": true
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"type": "refactor",
|
|
25
|
-
"section": "Refactor"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"type": "perf",
|
|
29
|
-
"section": "Performance"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"type": "test",
|
|
33
|
-
"hidden": true
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
## [0.1.2](https://github.com/isdk/json-repair.js/compare/v0.1.1...v0.1.2) (2026-01-30)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Features
|
|
9
|
-
|
|
10
|
-
* support balanced delimiter tracking in greedy capture ([51ba9c9](https://github.com/isdk/json-repair.js/commit/51ba9c939ae687b9da4b8574f2af0af0f31a3c0e))
|
|
11
|
-
|
|
12
|
-
## 0.1.1 (2026-01-30)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### Features
|
|
16
|
-
|
|
17
|
-
* initial implementation of schema-guided json-repair with fuzzy matching and semantic coercion ([0b5c61d](https://github.com/isdk/json-repair.js/commit/0b5c61d4f059ddcdc6b47498f3bb4cfbb905409d))
|
|
18
|
-
* support JSON repair with missing or empty schema ([285873c](https://github.com/isdk/json-repair.js/commit/285873c5a6c2afa891c3cbea3296f13e2b11a4d0))
|
package/TODO
DELETED
|
File without changes
|