llmsdk_provider/json.rs
1//! JSON value re-exports used across the provider surface.
2//!
3//! Mirrors `@ai-sdk/provider`'s `json-value` module. We re-export
4//! [`serde_json::Value`] and friends so downstream crates have a single
5//! import point, plus a typed [`JsonSchema`] alias backed by
6//! [`schemars::Schema`] for the function-tool / response-format surfaces.
7// Rust guideline compliant 2026-02-21
8
9pub use serde_json::Value as JsonValue;
10
11/// JSON object map (`{ string: JsonValue }`), matching `serde_json::Map<String, Value>`.
12pub type JsonObject = serde_json::Map<String, JsonValue>;
13
14/// JSON schema describing a tool's input or a JSON response format.
15///
16/// Backed by [`schemars::Schema`] — a transparent newtype over
17/// [`serde_json::Value`] that implements [`serde::Serialize`] /
18/// [`serde::Deserialize`] and matches `JSONSchema7` on the wire.
19///
20/// # Construct
21///
22/// - From a literal: [`schemars::json_schema!`].
23/// - From a derived type: [`schemars::schema_for!`].
24/// - From an existing JSON value: `serde_json::from_value(value)` (returns
25/// `Result<JsonSchema, _>` because [`schemars::Schema`] validates on
26/// deserialize).
27///
28/// # Examples
29///
30/// ```
31/// use llmsdk_provider::json::JsonSchema;
32/// use serde_json::json;
33///
34/// let schema: JsonSchema = serde_json::from_value(json!({
35/// "type": "object",
36/// "properties": { "city": { "type": "string" } }
37/// })).unwrap();
38/// assert_eq!(schema.as_object().unwrap().get("type").unwrap(), "object");
39/// ```
40pub type JsonSchema = schemars::Schema;