Skip to content

JsonParsing

Namespace: Vercel.AI.ProviderUtils

public static class JsonParsing

Parses JSON text, optionally checking it against a JSON Schema document.

Inheritance: object

View source

public static bool IsParsable(string text)

True when Parse(string) accepts <code class=“paramref”>text</code>.

Parameters

Name Type Description
text string

Returns: bool

View source

public static JsonElement Parse(string text, JsonNode? schema = null)

Parses <code class=“paramref”>text</code>. Schema failures throw TypeValidationException.

Parameters

Name Type Description
text string
schema JsonNode

Returns: JsonElement

View source

public static JsonParseResult SafeParse(string text, JsonNode? schema = null)

Parses <code class=“paramref”>text</code> without throwing for invalid JSON or schema mismatches.

Parameters

Name Type Description
text string
schema JsonNode

Returns: JsonParseResult

View source

public static JsonParseResult SafeValidateTypes(JsonElement value, JsonNode schema)

Validates <code class=“paramref”>value</code> without throwing. Maps to safeValidateTypes.

Parameters

Name Type Description
value JsonElement
schema JsonNode

Returns: JsonParseResult

View source

public static JsonElement ValidateTypes(JsonElement value, JsonNode schema)

Returns <code class=“paramref”>value</code> projected through <code class=“paramref”>schema</code>. Maps to validateTypes.

Parameters

Name Type Description
value JsonElement
schema JsonNode

Returns: JsonElement

Exceptions

Type Condition
TypeValidationException The value does not match the schema.

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product