Firebase. AI. JsonSchema
A JsonSchema object allows the definition of input and output data types.
Summary
These types can be objects, but also primitives and arrays. Represents a select subset of an JsonSchema object.
Public types |
|
|---|---|
SchemaType
|
enum The value type of a Schema. |
Properties |
|
|---|---|
AnyOfSchemas
|
IReadOnlyList< JsonSchema >
An array of
JsonSchema objects. |
Description
|
string
A human-readable explanation of the purpose of the schema or property.
|
EnumValues
|
IReadOnlyList< string >
Possible values of the element of type "String" with "enum" format.
|
Format
|
string
The format of the data.
|
Items
|
JsonSchema of the elements of type "Array".
|
MaxItems
|
int
An integer specifying the maximum number of items the generated "Array" must contain.
|
Maximum
|
double
The maximum value of a numeric type.
|
MinItems
|
int
An integer specifying the minimum number of items the generated "Array" must contain.
|
Minimum
|
double
The minimum value of a numeric type.
|
Nullable
|
bool
Indicates if the value may be null.
|
Properties
|
IReadOnlyDictionary< string, JsonSchema >
Properties of type "Object".
|
PropertyOrdering
|
IReadOnlyList< string >
A specific hint provided to the Gemini model, suggesting the order in which the keys should appear in the generated JSON string.
|
RequiredProperties
|
IReadOnlyList< string >
Required properties of type "Object".
|
SchemaDefinitions
|
IReadOnlyDictionary< string, JsonSchema >
A set of JsonSchema definitions, that can be used be JsonSchema.Ref objects.
|
SchemaReference
|
string
A reference to a JsonSchema defined in a parent Object's SchemaDefinitions.
|
Title
|
string
A human-readable name/summary for the schema or a specific property.
|
Type
|
The data type.
|
Public static functions |
|
|---|---|
AnyOf(IEnumerable< JsonSchema > schemas)
|
Returns a
JsonSchema representing a value that must conform to any (one or more) of the provided sub-schemas. |
Array(JsonSchema items, string description, bool nullable, int? minItems, int? maxItems)
|
Returns a
JsonSchema for an array. |
Boolean(string description, bool nullable)
|
Returns a
JsonSchema representing a boolean value. |
Double(string description, bool nullable, double? minimum, double? maximum)
|
Returns a
JsonSchema for a double-precision floating-point number. |
Enum(IEnumerable< string > values, string description, bool nullable)
|
Returns a
JsonSchema for an enumeration. |
Float(string description, bool nullable, float? minimum, float? maximum)
|
Returns a
JsonSchema for a single-precision floating-point number. |
FromType(Type type, string description)
|
Generates a JsonSchema for the given type, using reflection.
|
Int(string description, bool nullable, int? minimum, int? maximum)
|
Returns a
JsonSchema for a 32-bit signed integer number. |
Long(string description, bool nullable, long? minimum, long? maximum)
|
Returns a
JsonSchema for a 64-bit signed integer number. |
Object(IDictionary< string, JsonSchema > properties, IEnumerable< string > optionalProperties, IEnumerable< string > propertyOrdering, string description, string title, bool nullable, IDictionary< string, JsonSchema > schemaDefinitions)
|
Returns a
JsonSchema representing an object. |
Ref(string schemaReference)
|
Returns a
JsonSchema that references a definition in a parent object. |
String(string description, bool nullable, StringFormat? format)
|
Returns a
JsonSchema for a string. |
Structs |
|
|---|---|
|
Firebase. |
Modifiers describing the expected format of a string |
Public types
Properties
AnyOfSchemas
IReadOnlyList< JsonSchema > AnyOfSchemas
An array of JsonSchema objects.
The generated data must be valid against any (one or more) of the schemas listed in this array. This allows specifying multiple possible structures or types for a single field.
For example, a value could be either a String or an Int: ``` JsonSchema.AnyOf(new [] { JsonSchema.String(), JsonSchema.Int() }) ```
Description
string Description
A human-readable explanation of the purpose of the schema or property.
While not strictly enforced on the value itself, good descriptions significantly help the model understand the context and generate more relevant and accurate output.
EnumValues
IReadOnlyList< string > EnumValues
Possible values of the element of type "String" with "enum" format.
Format
string Format
The format of the data.
MaxItems
int MaxItems
An integer specifying the maximum number of items the generated "Array" must contain.
Maximum
double Maximum
The maximum value of a numeric type.
MinItems
int MinItems
An integer specifying the minimum number of items the generated "Array" must contain.
Minimum
double Minimum
The minimum value of a numeric type.
Nullable
bool Nullable
Indicates if the value may be null.
PropertyOrdering
IReadOnlyList< string > PropertyOrdering
A specific hint provided to the Gemini model, suggesting the order in which the keys should appear in the generated JSON string.
Important: Standard JSON objects are inherently unordered collections of key-value pairs. While the model will try to respect PropertyOrdering in its textual JSON output, subsequent parsing into native C# objects (like Dictionaries) might not preserve this order. This parameter primarily affects the raw JSON string serialization.
RequiredProperties
IReadOnlyList< string > RequiredProperties
Required properties of type "Object".
SchemaDefinitions
IReadOnlyDictionary< string, JsonSchema > SchemaDefinitions
A set of JsonSchema definitions, that can be used be JsonSchema.Ref objects.
SchemaReference
string SchemaReference
A reference to a JsonSchema defined in a parent Object's SchemaDefinitions.
Should generally be the form "#/$defs/schema_name"
Title
string Title
A human-readable name/summary for the schema or a specific property.
This helps document the schema's purpose but doesn't typically constrain the generated value. It can subtly guide the model by clarifying the intent of a field.
Public static functions
AnyOf
JsonSchema AnyOf( IEnumerable< JsonSchema > schemas )
Returns a JsonSchema representing a value that must conform to any (one or more) of the provided sub-schemas.
This schema instructs the model to produce data that is valid against at least one of the schemas listed in the schemas array. This is useful when a field can accept multiple distinct types or structures.
| Details | |||
|---|---|---|---|
| Parameters |
|
Array
JsonSchema Array( JsonSchema items, string description, bool nullable, int? minItems, int? maxItems )
Returns a JsonSchema for an array.
| Details | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Parameters |
|
Boolean
JsonSchema Boolean( string description, bool nullable )
Returns a JsonSchema representing a boolean value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
Double
JsonSchema Double( string description, bool nullable, double? minimum, double? maximum )
Returns a JsonSchema for a double-precision floating-point number.
| Details | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Parameters |
|
Enum
JsonSchema Enum( IEnumerable< string > values, string description, bool nullable )
Returns a JsonSchema for an enumeration.
For example, the cardinal directions can be represented as: ``` JsonSchema.Enum(new string[]{ "North", "East", "South", "West" }, "Cardinal directions") ```
| Details | |||||||
|---|---|---|---|---|---|---|---|
| Parameters |
|
Float
JsonSchema Float( string description, bool nullable, float? minimum, float? maximum )
Returns a JsonSchema for a single-precision floating-point number.
Important: This JsonSchema provides a hint to the model that it should generate a single-precision floating-point number, but only guarantees that the value will be a number. Therefore it's possible that decoding it as a float could overflow.
| Details | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Parameters |
|
FromType
JsonSchema FromType( Type type, string description )
Generates a JsonSchema for the given type, using reflection.
Note that if the type implements: static JsonSchema ToJsonSchema(), that function will be called to generate the JsonSchema.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
Int
JsonSchema Int( string description, bool nullable, int? minimum, int? maximum )
Returns a JsonSchema for a 32-bit signed integer number.
Important: This JsonSchema provides a hint to the model that it should generate a 32-bit integer, but only guarantees that the value will be an integer. Therefore it's possible that decoding it as an int could overflow.
| Details | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Parameters |
|
Long
JsonSchema Long( string description, bool nullable, long? minimum, long? maximum )
Returns a JsonSchema for a 64-bit signed integer number.
| Details | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Parameters |
|
Object
JsonSchema Object( IDictionary< string, JsonSchema > properties, IEnumerable< string > optionalProperties, IEnumerable< string > propertyOrdering, string description, string title, bool nullable, IDictionary< string, JsonSchema > schemaDefinitions )
Returns a JsonSchema representing an object.
This schema instructs the model to produce data of type "Object", which has keys of type "String" and values of any other data type (including nested "Objects"s).
Example: A City could be represented with the following object JsonSchema. ``` JsonSchema.Object(properties: new Dictionary() { { "name", JsonSchema.String() }, { "population", JsonSchema.Integer() } }) ```
| Details | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Parameters |
|
Ref
JsonSchema Ref( string schemaReference )
Returns a JsonSchema that references a definition in a parent object.
| Details | |||
|---|---|---|---|
| Parameters |
|
String
JsonSchema String( string description, bool nullable, StringFormat? format )
Returns a JsonSchema for a string.
| Details | |||||||
|---|---|---|---|---|---|---|---|
| Parameters |
|