@solvers-hub/llm-json 0.1.6 → 0.1.8

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 (37) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +117 -108
  3. package/dist/{src/corrector.js → corrector.js} +11 -12
  4. package/dist/{src/extractor.d.ts → extractor.d.ts} +1 -1
  5. package/dist/{src/extractor.js → extractor.js} +12 -23
  6. package/dist/{src/validator.js → validator.js} +3 -0
  7. package/docs/classes/LlmJson.html +5 -5
  8. package/docs/index.html +9 -4
  9. package/docs/interfaces/ExtractOptions.html +3 -3
  10. package/docs/interfaces/ExtractResult.html +4 -4
  11. package/docs/interfaces/JsonBlock.html +6 -6
  12. package/docs/interfaces/JsonParseError.html +4 -4
  13. package/docs/interfaces/SchemaDefinition.html +3 -3
  14. package/docs/interfaces/ValidationResult.html +5 -5
  15. package/docs-md/README.md +108 -59
  16. package/docs-md/classes/LlmJson.md +147 -147
  17. package/docs-md/interfaces/ExtractOptions.md +49 -29
  18. package/docs-md/interfaces/ExtractResult.md +49 -36
  19. package/docs-md/interfaces/JsonBlock.md +75 -75
  20. package/docs-md/interfaces/JsonParseError.md +49 -49
  21. package/docs-md/interfaces/SchemaDefinition.md +36 -0
  22. package/docs-md/interfaces/ValidationResult.md +62 -0
  23. package/docs-md/modules.md +28 -26
  24. package/examples/array-example.ts +69 -0
  25. package/{dist/examples/example.js → examples/example.ts} +48 -43
  26. package/examples/schema-validation-example.ts +140 -0
  27. package/examples/schema-validation-examples.ts +248 -0
  28. package/package.json +6 -6
  29. package/dist/examples/example.d.ts +0 -1
  30. /package/dist/{src/array-extractor.d.ts → array-extractor.d.ts} +0 -0
  31. /package/dist/{src/array-extractor.js → array-extractor.js} +0 -0
  32. /package/dist/{src/corrector.d.ts → corrector.d.ts} +0 -0
  33. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  34. /package/dist/{src/index.js → index.js} +0 -0
  35. /package/dist/{src/types.d.ts → types.d.ts} +0 -0
  36. /package/dist/{src/types.js → types.js} +0 -0
  37. /package/dist/{src/validator.d.ts → validator.d.ts} +0 -0
@@ -1,10 +1,10 @@
1
1
  <!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>ValidationResult | @solvers-hub/llm-json</title><meta name="description" content="Documentation for @solvers-hub/llm-json"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@solvers-hub/llm-json</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@solvers-hub/llm-json</a></li><li><a href="ValidationResult.html">ValidationResult</a></li></ul><h1>Interface ValidationResult</h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>Result of schema validation for a JSON object.</p>
2
- </div><div class="tsd-comment tsd-typography"></div></section><div class="tsd-signature"><span class="tsd-signature-keyword">interface </span><span class="tsd-kind-interface">ValidationResult</span> <span class="tsd-signature-symbol">{ </span><br/><span>    </span><a class="tsd-kind-property" href="ValidationResult.html#isValid">isValid</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">; </span><br/><span>    </span><a class="tsd-kind-property" href="ValidationResult.html#json">json</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">; </span><br/><span>    </span><a class="tsd-kind-property" href="ValidationResult.html#matchedSchema">matchedSchema</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span><br/><span>    </span><a class="tsd-kind-property" href="ValidationResult.html#validationErrors">validationErrors</a><span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">; </span><br/><span class="tsd-signature-symbol">}</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/de4fb5a4209b6f115ef863cd3e7016e7b565b262/src/types.ts#L37">types.ts:37</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex="0"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg> Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="ValidationResult.html#isValid" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>is<wbr/>Valid</span></a>
2
+ </div><div class="tsd-comment tsd-typography"></div></section><div class="tsd-signature"><span class="tsd-signature-keyword">interface </span><span class="tsd-kind-interface">ValidationResult</span> <span class="tsd-signature-symbol">{ </span><br/><span>    </span><a class="tsd-kind-property" href="ValidationResult.html#isValid">isValid</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">; </span><br/><span>    </span><a class="tsd-kind-property" href="ValidationResult.html#json">json</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">; </span><br/><span>    </span><a class="tsd-kind-property" href="ValidationResult.html#matchedSchema">matchedSchema</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span><br/><span>    </span><a class="tsd-kind-property" href="ValidationResult.html#validationErrors">validationErrors</a><span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">; </span><br/><span class="tsd-signature-symbol">}</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/d73b7f27d11f55658fe6f40fcf81e46cbf91f7f4/src/types.ts#L37">types.ts:37</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex="0"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg> Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="ValidationResult.html#isValid" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>is<wbr/>Valid</span></a>
3
3
  <a href="ValidationResult.html#json" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>json</span></a>
4
4
  <a href="ValidationResult.html#matchedSchema" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>matched<wbr/>Schema</span></a>
5
5
  <a href="ValidationResult.html#validationErrors" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>validation<wbr/>Errors?</span></a>
6
6
  </div></section></div></details></section></section><section class="tsd-panel-group tsd-member-group"><h2>Properties</h2><section class="tsd-panel tsd-member"><a id="isValid" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>is<wbr/>Valid</span><a href="#isValid" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">is<wbr/>Valid</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div><div class="tsd-comment tsd-typography"><p>Whether the JSON is valid according to the matched schema.</p>
7
- </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/de4fb5a4209b6f115ef863cd3e7016e7b565b262/src/types.ts#L51">types.ts:51</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="json" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>json</span><a href="#json" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">json</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div><div class="tsd-comment tsd-typography"><p>The JSON object that was validated.</p>
8
- </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/de4fb5a4209b6f115ef863cd3e7016e7b565b262/src/types.ts#L41">types.ts:41</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="matchedSchema" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>matched<wbr/>Schema</span><a href="#matchedSchema" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">matched<wbr/>Schema</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>The name of the schema that matched, or null if no schema matched.</p>
9
- </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/de4fb5a4209b6f115ef863cd3e7016e7b565b262/src/types.ts#L46">types.ts:46</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="validationErrors" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>validation<wbr/>Errors</span><a href="#validationErrors" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">validation<wbr/>Errors</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></div><div class="tsd-comment tsd-typography"><p>Validation errors if any, or undefined if validation passed.</p>
10
- </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/de4fb5a4209b6f115ef863cd3e7016e7b565b262/src/types.ts#L56">types.ts:56</a></li></ul></aside></section></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#isValid" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>is<wbr/>Valid</span></a><a href="#json" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>json</span></a><a href="#matchedSchema" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>matched<wbr/>Schema</span></a><a href="#validationErrors" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>validation<wbr/>Errors</span></a></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@solvers-hub/llm-json</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
7
+ </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/d73b7f27d11f55658fe6f40fcf81e46cbf91f7f4/src/types.ts#L51">types.ts:51</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="json" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>json</span><a href="#json" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">json</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div><div class="tsd-comment tsd-typography"><p>The JSON object that was validated.</p>
8
+ </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/d73b7f27d11f55658fe6f40fcf81e46cbf91f7f4/src/types.ts#L41">types.ts:41</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="matchedSchema" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>matched<wbr/>Schema</span><a href="#matchedSchema" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">matched<wbr/>Schema</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>The name of the schema that matched, or null if no schema matched.</p>
9
+ </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/d73b7f27d11f55658fe6f40fcf81e46cbf91f7f4/src/types.ts#L46">types.ts:46</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="validationErrors" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>validation<wbr/>Errors</span><a href="#validationErrors" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">validation<wbr/>Errors</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></div><div class="tsd-comment tsd-typography"><p>Validation errors if any, or undefined if validation passed.</p>
10
+ </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/d73b7f27d11f55658fe6f40fcf81e46cbf91f7f4/src/types.ts#L56">types.ts:56</a></li></ul></aside></section></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#isValid" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>is<wbr/>Valid</span></a><a href="#json" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>json</span></a><a href="#matchedSchema" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>matched<wbr/>Schema</span></a><a href="#validationErrors" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>validation<wbr/>Errors</span></a></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@solvers-hub/llm-json</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
package/docs-md/README.md CHANGED
@@ -1,59 +1,108 @@
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
- - **TypeScript Support**: Written in TypeScript with full type definitions
21
-
22
- ## Quick Start
23
-
24
- ### Installation
25
-
26
- ```bash
27
- npm install llm-json
28
- ```
29
-
30
- ### Basic Usage
31
-
32
- ```typescript
33
- import { LlmJson } from 'llm-json';
34
-
35
- const llmOutput = `Here's some text followed by JSON:
36
-
37
- {
38
- "name": "John",
39
- "age": 30,
40
- "skills": ["JavaScript", "TypeScript", "React"]
41
- }`;
42
-
43
- const llmJson = new LlmJson({ attemptCorrection: true });
44
- const { text, json } = llmJson.extract(llmOutput);
45
-
46
- console.log(text); // ['Here\'s some text followed by JSON:']
47
- console.log(json); // [{ name: 'John', age: 30, skills: ['JavaScript', 'TypeScript', 'React'] }]
48
- ```
49
-
50
- ## Documentation
51
-
52
- For detailed documentation including API references and examples:
53
-
54
- - [API Documentation](./docs/README.md)
55
- - [Examples](./docs/examples.md)
56
-
57
- ## License
58
-
59
- MIT © 2023
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 +1,147 @@
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/4d60f7fa6cdcace0d353b33e3d79c6fd33db1860/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/4d60f7fa6cdcace0d353b33e3d79c6fd33db1860/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/4d60f7fa6cdcace0d353b33e3d79c6fd33db1860/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/4d60f7fa6cdcace0d353b33e3d79c6fd33db1860/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/4d60f7fa6cdcace0d353b33e3d79c6fd33db1860/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/4d60f7fa6cdcace0d353b33e3d79c6fd33db1860/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/4d60f7fa6cdcace0d353b33e3d79c6fd33db1860/src/index.ts#L27)
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,29 +1,49 @@
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
-
13
- ## Properties
14
-
15
- ### attemptCorrection
16
-
17
- • `Optional` **attemptCorrection**: `boolean`
18
-
19
- Whether to attempt to correct malformed JSON.
20
-
21
- **`Default`**
22
-
23
- ```ts
24
- false
25
- ```
26
-
27
- #### Defined in
28
-
29
- [types.ts:9](https://github.com/solvers-hub/llm-json/blob/4d60f7fa6cdcace0d353b33e3d79c6fd33db1860/src/types.ts#L9)
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)