Skip to content

nimgent/structured_output/jsonschema_parse

This page is generated from the module’s exported API and ## documentation comments.

Loose JSON extraction and partial JSON repair used by structured output.

A complete JSON value, or the first object/array after leading prose.

proc extractJson(s: string): JsonNode {.raises: [],
tags: [ReadIOEffect, WriteIOEffect],
forbids: [].}

Returns: JsonNode.

Name Type Default
s string

View source

Close a prefix of JSON so parseJson can read it. Port of AI SDK fixJson.

proc fixJson(input: string): string {.raises: [], tags: [], forbids: [].}

Returns: string.

Name Type Default
input string

View source

Parse complete JSON, or a repaired prefix (AI SDK parsePartialJson).

proc parsePartialJson(s: string): tuple[value: JsonNode, state: PartialParse] {.
raises: [], tags: [ReadIOEffect, WriteIOEffect], forbids: [].}

Returns: tuple[value: JsonNode, state: PartialParse].

Name Type Default
s string

View source

Result of parsing or repairing a partial JSON value.

PartialParse = enum
ppUndefined, ppSuccess, ppRepaired, ppFailed

View source