API Documentation
Schema Documentation
Enums (Enumerated Values)
Enums (short for "enumerations") are a way to specify that a property must have one of a predefined set of values. This is useful when you want to constrain the possible values of a field.
Basic Enums
To define an enum, use the enum
keyword with an array of possible values.
{ "type": "object", "properties": { "name": { "type": "string", "description": "The person's name" }, "status": { "type": "string", "description": "The person's current status", "enum": ["active", "inactive", "pending"] } } }
Example Input:
John is currently an active member of our organization.
Example Output:
{ "name": "John", "status": "active" }
Pro Tip:
The AI will map similar words or phrases to the closest matching enum value. For example, "John is active in our community" would still map to "active" status.
Enums with Different Types
Enum values can be of different types, including strings, numbers, booleans, and null.
{ "type": "object", "properties": { "name": { "type": "string", "description": "The product name" }, "priority": { "description": "The product priority level", "enum": [1, 2, 3, "high", "medium", "low", null] } } }
Example Input:
Our Premium Widget has been assigned high priority for the upcoming release.
Example Output:
{ "name": "Premium Widget", "priority": "high" }
Alternative Example Input:
The Basic Connector is given priority level 2 for development.
Alternative Example Output:
{ "name": "Basic Connector", "priority": 2 }
Enum Descriptions
You can provide descriptions for enum values to help the AI better understand the context and meaning of each value.
{ "type": "object", "properties": { "name": { "type": "string", "description": "The person's name" }, "employmentStatus": { "type": "string", "description": "The person's employment status", "enum": ["full-time", "part-time", "contract", "freelance", "unemployed"], "enumDescriptions": { "full-time": "Working 40 hours per week or more", "part-time": "Working less than 40 hours per week", "contract": "Working on a fixed-term contract", "freelance": "Working on a project-by-project basis", "unemployed": "Not currently employed" } } } }
Example Input:
Maria works about 25 hours a week at the company.
Example Output:
{ "name": "Maria", "employmentStatus": "part-time" }
Note:
The enumDescriptions
field is not part of the standard JSON Schema but is a custom extension used by JSON Anything to provide better context to the AI.
Enums with Arrays
You can use enums with array items to ensure each item in an array matches one of the predefined values.
{ "type": "object", "properties": { "productName": { "type": "string", "description": "The product name" }, "supportedPaymentMethods": { "type": "array", "description": "List of supported payment methods", "items": { "type": "string", "enum": ["credit_card", "paypal", "bank_transfer", "crypto", "apple_pay", "google_pay"] } } } }
Example Input:
Our Premium Service supports payments via credit cards, PayPal, and Apple Pay.
Example Output:
{ "productName": "Premium Service", "supportedPaymentMethods": [ "credit_card", "paypal", "apple_pay" ] }
Complex Example with Multiple Enums
Enums can be used in multiple fields within the same schema, including in nested objects.
{ "type": "object", "properties": { "order": { "type": "object", "properties": { "id": { "type": "string", "description": "Order ID" }, "status": { "type": "string", "description": "Order status", "enum": ["pending", "processing", "shipped", "delivered", "cancelled"] }, "shippingMethod": { "type": "string", "description": "Shipping method", "enum": ["standard", "express", "overnight"] }, "paymentStatus": { "type": "string", "description": "Payment status", "enum": ["authorized", "paid", "refunded", "failed"] } } }, "customer": { "type": "object", "properties": { "name": { "type": "string", "description": "Customer name" }, "type": { "type": "string", "description": "Customer type", "enum": ["individual", "business"] } } } } }
Example Input:
Order #12345 has been shipped via express shipping. Payment has been received. The order was placed by John Smith, who is an individual customer.
Example Output:
{ "order": { "id": "12345", "status": "shipped", "shippingMethod": "express", "paymentStatus": "paid" }, "customer": { "name": "John Smith", "type": "individual" } }
Best Practices for Enums
When using enums in your schemas, consider these best practices:
- Use descriptive values: Choose enum values that are clear and self-explanatory.
- Be consistent: Use consistent naming conventions for your enum values (e.g., all lowercase with underscores).
- Include descriptions: Adding descriptions for enum values helps the AI better understand the context.
- Limit the number of values: Keep the list of enum values manageable. Too many options can make it harder for the AI to extract the correct value.
- Consider synonyms: The AI will attempt to map similar terms to the enum values, but it helps to choose values that cover common variations.
Pro Tip:
If you find the AI is struggling to match text to the right enum value, try adding more context in the property description or using enumDescriptions
to provide examples.