@solvers-hub/llm-json 0.1.10 → 0.1.11

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.
Files changed (36) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -5
  3. package/docs/.nojekyll +0 -1
  4. package/docs/assets/highlight.css +0 -120
  5. package/docs/assets/icons.js +0 -15
  6. package/docs/assets/icons.svg +0 -1
  7. package/docs/assets/main.js +0 -59
  8. package/docs/assets/navigation.js +0 -1
  9. package/docs/assets/search.js +0 -1
  10. package/docs/assets/style.css +0 -1412
  11. package/docs/classes/LlmJson.html +0 -20
  12. package/docs/index.html +0 -68
  13. package/docs/interfaces/ExtractOptions.html +0 -11
  14. package/docs/interfaces/ExtractResult.html +0 -8
  15. package/docs/interfaces/JsonBlock.html +0 -12
  16. package/docs/interfaces/JsonParseError.html +0 -8
  17. package/docs/interfaces/SchemaDefinition.html +0 -6
  18. package/docs/interfaces/ValidationResult.html +0 -10
  19. package/docs/modules.html +0 -9
  20. package/docs-md/.nojekyll +0 -1
  21. package/docs-md/COMPREHENSIVE_GUIDE.md +0 -669
  22. package/docs-md/README.md +0 -108
  23. package/docs-md/classes/LlmJson.md +0 -147
  24. package/docs-md/interfaces/ExtractOptions.md +0 -49
  25. package/docs-md/interfaces/ExtractResult.md +0 -49
  26. package/docs-md/interfaces/JsonBlock.md +0 -75
  27. package/docs-md/interfaces/JsonParseError.md +0 -49
  28. package/docs-md/interfaces/SchemaDefinition.md +0 -36
  29. package/docs-md/interfaces/ValidationResult.md +0 -62
  30. package/docs-md/modules.md +0 -28
  31. package/examples/advanced-patterns-example.ts +0 -533
  32. package/examples/array-example.ts +0 -69
  33. package/examples/example.ts +0 -101
  34. package/examples/schema-validation-example.ts +0 -140
  35. package/examples/schema-validation-examples.ts +0 -248
  36. package/examples/zod-integration-example.ts +0 -431
package/docs-md/README.md DELETED
@@ -1,108 +0,0 @@
1
- @solvers-hub/llm-json / [Exports](modules.md)
2
-
3
- # LLM-JSON Extractor
4
-
5
- A TypeScript SDK for extracting and correcting JSON data from LLM outputs.
6
-
7
- [![npm version](https://badge.fury.io/js/llm-json.svg)](https://badge.fury.io/js/llm-json)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
-
10
- ## Overview
11
-
12
- LLM-JSON is a lightweight library designed to parse and extract JSON objects from large language model (LLM) outputs. It can handle multiple JSON objects within text, extract text separately from JSON, and even attempt to fix malformed JSON.
13
-
14
- ## Key Features
15
-
16
- - **Text/JSON Separation**: Cleanly separates text content from JSON data in LLM outputs
17
- - **Multiple JSON Support**: Extracts multiple JSON objects or arrays from a single input
18
- - **JSON Validation & Correction**: Automatically fixes common JSON formatting errors from LLMs
19
- - **Code Block Support**: Extracts JSON from markdown code blocks (```json)
20
- - **Schema Validation**: Validates extracted JSON against provided schemas
21
- - **TypeScript Support**: Written in TypeScript with full type definitions
22
-
23
- ## Quick Start
24
-
25
- ### Installation
26
-
27
- ```bash
28
- npm install @solvers-hub/llm-json
29
- ```
30
-
31
- ### Basic Usage
32
-
33
- ```typescript
34
- import { LlmJson } from '@solvers-hub/llm-json';
35
-
36
- const llmOutput = `Here's some text followed by JSON:
37
-
38
- {
39
- "name": "John",
40
- "age": 30,
41
- "skills": ["JavaScript", "TypeScript", "React"]
42
- }`;
43
-
44
- const llmJson = new LlmJson({ attemptCorrection: true });
45
- const { text, json } = llmJson.extract(llmOutput);
46
-
47
- console.log(text); // ['Here\'s some text followed by JSON:']
48
- console.log(json); // [{ name: 'John', age: 30, skills: ['JavaScript', 'TypeScript', 'React'] }]
49
- ```
50
-
51
- ### Schema Validation
52
-
53
- You can validate extracted JSON against schemas:
54
-
55
- ```typescript
56
- import { LlmJson } from '@solvers-hub/llm-json';
57
-
58
- const schemas = [
59
- {
60
- name: 'person',
61
- schema: {
62
- type: 'object',
63
- properties: {
64
- name: { type: 'string' },
65
- age: { type: 'integer' }
66
- },
67
- required: ['name', 'age']
68
- }
69
- }
70
- ];
71
-
72
- const llmJson = new LlmJson({
73
- attemptCorrection: true,
74
- schemas
75
- });
76
-
77
- const llmOutput = `Here's a person: {"name": "John", "age": 30}
78
- And some other data: {"title": "Meeting notes"}`;
79
- const result = llmJson.extract(llmOutput);
80
-
81
- // Note: All extracted JSON objects are included in the json array
82
- console.log(result.json);
83
- // [
84
- // { name: 'John', age: 30 },
85
- // { title: 'Meeting notes' }
86
- // ]
87
-
88
- // The validatedJson array includes validation results for each JSON object
89
- console.log(result.validatedJson);
90
- // [
91
- // {
92
- // json: { name: 'John', age: 30 },
93
- // matchedSchema: 'person',
94
- // isValid: true
95
- // },
96
- // {
97
- // json: { title: 'Meeting notes' },
98
- // matchedSchema: null,
99
- // isValid: false,
100
- // validationErrors: [...] // Validation errors
101
- // }
102
- // ]
103
-
104
- ```
105
-
106
- ## License
107
-
108
- MIT © 2025
@@ -1,147 +0,0 @@
1
- [@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / LlmJson
2
-
3
- # Class: LlmJson
4
-
5
- Main factory class for the LLM-JSON extractor SDK.
6
-
7
- ## Table of contents
8
-
9
- ### Constructors
10
-
11
- - [constructor](LlmJson.md#constructor)
12
-
13
- ### Properties
14
-
15
- - [arrayExtractor](LlmJson.md#arrayextractor)
16
- - [objectExtractor](LlmJson.md#objectextractor)
17
- - [instance](LlmJson.md#instance)
18
-
19
- ### Methods
20
-
21
- - [extract](LlmJson.md#extract)
22
- - [extractAll](LlmJson.md#extractall)
23
- - [getInstance](LlmJson.md#getinstance)
24
-
25
- ## Constructors
26
-
27
- ### constructor
28
-
29
- • **new LlmJson**(`options?`): [`LlmJson`](LlmJson.md)
30
-
31
- Creates a new LlmJson instance with the specified options.
32
-
33
- #### Parameters
34
-
35
- | Name | Type | Description |
36
- | :------ | :------ | :------ |
37
- | `options` | [`ExtractOptions`](../interfaces/ExtractOptions.md) | Configuration options for extraction. |
38
-
39
- #### Returns
40
-
41
- [`LlmJson`](LlmJson.md)
42
-
43
- #### Defined in
44
-
45
- [index.ts:17](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L17)
46
-
47
- ## Properties
48
-
49
- ### arrayExtractor
50
-
51
- • `Private` **arrayExtractor**: `JsonArrayExtractor`
52
-
53
- #### Defined in
54
-
55
- [index.ts:11](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L11)
56
-
57
- ___
58
-
59
- ### objectExtractor
60
-
61
- • `Private` **objectExtractor**: `JsonExtractor`
62
-
63
- #### Defined in
64
-
65
- [index.ts:10](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L10)
66
-
67
- ___
68
-
69
- ### instance
70
-
71
- ▪ `Static` `Private` **instance**: [`LlmJson`](LlmJson.md)
72
-
73
- #### Defined in
74
-
75
- [index.ts:9](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L9)
76
-
77
- ## Methods
78
-
79
- ### extract
80
-
81
- ▸ **extract**(`input`): [`ExtractResult`](../interfaces/ExtractResult.md)
82
-
83
- Extract JSON objects and text from a string input.
84
-
85
- #### Parameters
86
-
87
- | Name | Type | Description |
88
- | :------ | :------ | :------ |
89
- | `input` | `string` | The input string that may contain JSON. |
90
-
91
- #### Returns
92
-
93
- [`ExtractResult`](../interfaces/ExtractResult.md)
94
-
95
- An object containing arrays of extracted text and JSON.
96
-
97
- #### Defined in
98
-
99
- [index.ts:39](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L39)
100
-
101
- ___
102
-
103
- ### extractAll
104
-
105
- ▸ **extractAll**(`input`): [`ExtractResult`](../interfaces/ExtractResult.md)
106
-
107
- Extract JSON objects, arrays, and text from a string input.
108
-
109
- #### Parameters
110
-
111
- | Name | Type | Description |
112
- | :------ | :------ | :------ |
113
- | `input` | `string` | The input string that may contain JSON. |
114
-
115
- #### Returns
116
-
117
- [`ExtractResult`](../interfaces/ExtractResult.md)
118
-
119
- An object containing arrays of extracted text and JSON.
120
-
121
- #### Defined in
122
-
123
- [index.ts:48](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L48)
124
-
125
- ___
126
-
127
- ### getInstance
128
-
129
- ▸ **getInstance**(`options?`): [`LlmJson`](LlmJson.md)
130
-
131
- Get or create a singleton instance of LlmJson.
132
-
133
- #### Parameters
134
-
135
- | Name | Type | Description |
136
- | :------ | :------ | :------ |
137
- | `options` | [`ExtractOptions`](../interfaces/ExtractOptions.md) | Configuration options for extraction. |
138
-
139
- #### Returns
140
-
141
- [`LlmJson`](LlmJson.md)
142
-
143
- The LlmJson singleton instance.
144
-
145
- #### Defined in
146
-
147
- [index.ts:27](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L27)
@@ -1,49 +0,0 @@
1
- [@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / ExtractOptions
2
-
3
- # Interface: ExtractOptions
4
-
5
- Options for JSON extraction.
6
-
7
- ## Table of contents
8
-
9
- ### Properties
10
-
11
- - [attemptCorrection](ExtractOptions.md#attemptcorrection)
12
- - [schemas](ExtractOptions.md#schemas)
13
-
14
- ## Properties
15
-
16
- ### attemptCorrection
17
-
18
- • `Optional` **attemptCorrection**: `boolean`
19
-
20
- Whether to attempt to correct malformed JSON.
21
-
22
- **`Default`**
23
-
24
- ```ts
25
- false
26
- ```
27
-
28
- #### Defined in
29
-
30
- [types.ts:9](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L9)
31
-
32
- ___
33
-
34
- ### schemas
35
-
36
- • `Optional` **schemas**: [`SchemaDefinition`](SchemaDefinition.md)[]
37
-
38
- JSON schemas to validate extracted JSON against.
39
- If provided, the extracted JSON will be validated against these schemas.
40
-
41
- **`Default`**
42
-
43
- ```ts
44
- undefined
45
- ```
46
-
47
- #### Defined in
48
-
49
- [types.ts:16](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L16)
@@ -1,49 +0,0 @@
1
- [@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / ExtractResult
2
-
3
- # Interface: ExtractResult
4
-
5
- Result of the JSON extraction.
6
-
7
- ## Table of contents
8
-
9
- ### Properties
10
-
11
- - [json](ExtractResult.md#json)
12
- - [text](ExtractResult.md#text)
13
- - [validatedJson](ExtractResult.md#validatedjson)
14
-
15
- ## Properties
16
-
17
- ### json
18
-
19
- • **json**: `any`[]
20
-
21
- Array of parsed JSON objects extracted from the input.
22
-
23
- #### Defined in
24
-
25
- [types.ts:71](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L71)
26
-
27
- ___
28
-
29
- ### text
30
-
31
- • **text**: `string`[]
32
-
33
- Array of text blocks extracted from the input.
34
-
35
- #### Defined in
36
-
37
- [types.ts:66](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L66)
38
-
39
- ___
40
-
41
- ### validatedJson
42
-
43
- • `Optional` **validatedJson**: [`ValidationResult`](ValidationResult.md)[]
44
-
45
- Array of validated JSON results, only present if schemas were provided.
46
-
47
- #### Defined in
48
-
49
- [types.ts:76](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L76)
@@ -1,75 +0,0 @@
1
- [@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / JsonBlock
2
-
3
- # Interface: JsonBlock
4
-
5
- Information about a detected JSON block.
6
-
7
- ## Table of contents
8
-
9
- ### Properties
10
-
11
- - [endIndex](JsonBlock.md#endindex)
12
- - [parsed](JsonBlock.md#parsed)
13
- - [raw](JsonBlock.md#raw)
14
- - [startIndex](JsonBlock.md#startindex)
15
- - [wasCorrected](JsonBlock.md#wascorrected)
16
-
17
- ## Properties
18
-
19
- ### endIndex
20
-
21
- • **endIndex**: `number`
22
-
23
- The end index of the JSON block in the input string.
24
-
25
- #### Defined in
26
-
27
- [types.ts:96](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L96)
28
-
29
- ___
30
-
31
- ### parsed
32
-
33
- • `Optional` **parsed**: `any`
34
-
35
- The parsed JSON object.
36
-
37
- #### Defined in
38
-
39
- [types.ts:106](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L106)
40
-
41
- ___
42
-
43
- ### raw
44
-
45
- • **raw**: `string`
46
-
47
- The raw JSON string.
48
-
49
- #### Defined in
50
-
51
- [types.ts:86](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L86)
52
-
53
- ___
54
-
55
- ### startIndex
56
-
57
- • **startIndex**: `number`
58
-
59
- The start index of the JSON block in the input string.
60
-
61
- #### Defined in
62
-
63
- [types.ts:91](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L91)
64
-
65
- ___
66
-
67
- ### wasCorrected
68
-
69
- • `Optional` **wasCorrected**: `boolean`
70
-
71
- Whether the JSON was corrected.
72
-
73
- #### Defined in
74
-
75
- [types.ts:101](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L101)
@@ -1,49 +0,0 @@
1
- [@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / JsonParseError
2
-
3
- # Interface: JsonParseError
4
-
5
- Error information for JSON parsing failures.
6
-
7
- ## Table of contents
8
-
9
- ### Properties
10
-
11
- - [message](JsonParseError.md#message)
12
- - [position](JsonParseError.md#position)
13
- - [raw](JsonParseError.md#raw)
14
-
15
- ## Properties
16
-
17
- ### message
18
-
19
- • **message**: `string`
20
-
21
- The original error message.
22
-
23
- #### Defined in
24
-
25
- [types.ts:116](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L116)
26
-
27
- ___
28
-
29
- ### position
30
-
31
- • `Optional` **position**: `number`
32
-
33
- The position in the JSON string where the error occurred.
34
-
35
- #### Defined in
36
-
37
- [types.ts:126](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L126)
38
-
39
- ___
40
-
41
- ### raw
42
-
43
- • **raw**: `string`
44
-
45
- The raw JSON string that failed to parse.
46
-
47
- #### Defined in
48
-
49
- [types.ts:121](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L121)
@@ -1,36 +0,0 @@
1
- [@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / SchemaDefinition
2
-
3
- # Interface: SchemaDefinition
4
-
5
- Definition of a JSON schema for validation.
6
-
7
- ## Table of contents
8
-
9
- ### Properties
10
-
11
- - [name](SchemaDefinition.md#name)
12
- - [schema](SchemaDefinition.md#schema)
13
-
14
- ## Properties
15
-
16
- ### name
17
-
18
- • **name**: `string`
19
-
20
- A unique name for the schema to identify which schema matched.
21
-
22
- #### Defined in
23
-
24
- [types.ts:26](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L26)
25
-
26
- ___
27
-
28
- ### schema
29
-
30
- • **schema**: `object`
31
-
32
- The JSON schema object conforming to JSON Schema specification.
33
-
34
- #### Defined in
35
-
36
- [types.ts:31](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L31)
@@ -1,62 +0,0 @@
1
- [@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / ValidationResult
2
-
3
- # Interface: ValidationResult
4
-
5
- Result of schema validation for a JSON object.
6
-
7
- ## Table of contents
8
-
9
- ### Properties
10
-
11
- - [isValid](ValidationResult.md#isvalid)
12
- - [json](ValidationResult.md#json)
13
- - [matchedSchema](ValidationResult.md#matchedschema)
14
- - [validationErrors](ValidationResult.md#validationerrors)
15
-
16
- ## Properties
17
-
18
- ### isValid
19
-
20
- • **isValid**: `boolean`
21
-
22
- Whether the JSON is valid according to the matched schema.
23
-
24
- #### Defined in
25
-
26
- [types.ts:51](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L51)
27
-
28
- ___
29
-
30
- ### json
31
-
32
- • **json**: `any`
33
-
34
- The JSON object that was validated.
35
-
36
- #### Defined in
37
-
38
- [types.ts:41](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L41)
39
-
40
- ___
41
-
42
- ### matchedSchema
43
-
44
- • **matchedSchema**: ``null`` \| `string`
45
-
46
- The name of the schema that matched, or null if no schema matched.
47
-
48
- #### Defined in
49
-
50
- [types.ts:46](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L46)
51
-
52
- ___
53
-
54
- ### validationErrors
55
-
56
- • `Optional` **validationErrors**: `any`[]
57
-
58
- Validation errors if any, or undefined if validation passed.
59
-
60
- #### Defined in
61
-
62
- [types.ts:56](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L56)
@@ -1,28 +0,0 @@
1
- [@solvers-hub/llm-json](README.md) / Exports
2
-
3
- # @solvers-hub/llm-json
4
-
5
- ## Table of contents
6
-
7
- ### References
8
-
9
- - [default](modules.md#default)
10
-
11
- ### Classes
12
-
13
- - [LlmJson](classes/LlmJson.md)
14
-
15
- ### Interfaces
16
-
17
- - [ExtractOptions](interfaces/ExtractOptions.md)
18
- - [ExtractResult](interfaces/ExtractResult.md)
19
- - [JsonBlock](interfaces/JsonBlock.md)
20
- - [JsonParseError](interfaces/JsonParseError.md)
21
- - [SchemaDefinition](interfaces/SchemaDefinition.md)
22
- - [ValidationResult](interfaces/ValidationResult.md)
23
-
24
- ## References
25
-
26
- ### default
27
-
28
- Renames and re-exports [LlmJson](classes/LlmJson.md)