JSON Anything

Objects

Objects are the most common structure in JSON Schema. They allow you to create complex, nested data structures with multiple properties.

Basic Objects

An object is defined with "type": "object" and contains a set of properties, each with its own type and description.

{
  "type": "object",
  "properties": {
    "firstName": { 
      "type": "string",
      "description": "The person's first name"
    },
    "lastName": { 
      "type": "string",
      "description": "The person's last name"
    },
    "age": { 
      "type": "number",
      "description": "The person's age in years"
    }
  }
}

Example Input:

John Smith is 42 years old.

Example Output:

{
  "firstName": "John",
  "lastName": "Smith",
  "age": 42
}

Pro Tip:

Properties don't have to be in any specific order in the schema. The AI will extract them based on the information in the text.

Required Properties

You can specify which properties must be included in the output using the required array.

{
  "type": "object",
  "properties": {
    "name": { 
      "type": "string",
      "description": "The product name"
    },
    "price": { 
      "type": "number",
      "description": "The product price"
    },
    "description": { 
      "type": "string",
      "description": "The product description"
    },
    "sku": { 
      "type": "string",
      "description": "The product SKU code"
    }
  },
  "required": ["name", "price"]
}

Example Input:

We're selling a Premium Blender for $199.99. It's perfect for making smoothies and soups.

Example Output:

{
  "name": "Premium Blender",
  "price": 199.99,
  "description": "Perfect for making smoothies and soups"
}

Note:

If a required property cannot be found in the input text, the AI will make its best attempt to extract or infer the value. If it can't be reasonably inferred, the API may return an error.

Nested Objects

Objects can contain other objects as properties, allowing you to create complex, hierarchical data structures.

{
  "type": "object",
  "properties": {
    "name": { 
      "type": "string",
      "description": "The person's full name"
    },
    "address": { 
      "type": "object",
      "description": "The person's address",
      "properties": {
        "street": { 
          "type": "string",
          "description": "Street address"
        },
        "city": { 
          "type": "string",
          "description": "City name"
        },
        "state": { 
          "type": "string",
          "description": "State or province"
        },
        "zipCode": { 
          "type": "string",
          "description": "Postal or ZIP code"
        }
      },
      "required": ["city", "state"]
    },
    "contact": {
      "type": "object",
      "description": "Contact information",
      "properties": {
        "email": {
          "type": "string",
          "description": "Email address"
        },
        "phone": {
          "type": "string",
          "description": "Phone number"
        }
      }
    }
  }
}

Example Input:

Jennifer Watson lives at 123 Main St, Seattle, WA 98101. You can contact her at [email protected] or call 555-123-4567.

Example Output:

{
  "name": "Jennifer Watson",
  "address": {
    "street": "123 Main St",
    "city": "Seattle",
    "state": "WA",
    "zipCode": "98101"
  },
  "contact": {
    "email": "[email protected]",
    "phone": "555-123-4567"
  }
}

Deeply Nested Objects

Objects can be nested at multiple levels, allowing you to represent complex hierarchical data.

{
  "type": "object",
  "properties": {
    "company": { 
      "type": "string",
      "description": "The company name"
    },
    "headquarters": { 
      "type": "object",
      "description": "Company headquarters information",
      "properties": {
        "address": { 
          "type": "object",
          "properties": {
            "street": { "type": "string" },
            "city": { "type": "string" },
            "country": { "type": "string" }
          }
        },
        "employees": { 
          "type": "number",
          "description": "Number of employees at headquarters"
        }
      }
    },
    "founded": {
      "type": "number",
      "description": "Year the company was founded"
    }
  }
}

Example Input:

Acme Corporation was founded in 1985. Their headquarters are located at 100 Corporate Way, San Francisco, USA, where they have about 250 employees.

Example Output:

{
  "company": "Acme Corporation",
  "headquarters": {
    "address": {
      "street": "100 Corporate Way",
      "city": "San Francisco",
      "country": "USA"
    },
    "employees": 250
  },
  "founded": 1985
}

Additional Properties

By default, objects can include properties not specifically defined in the schema. You can control this behavior with additionalProperties.

{
  "type": "object",
  "properties": {
    "name": { 
      "type": "string",
      "description": "The product name"
    },
    "price": { 
      "type": "number",
      "description": "The product price"
    }
  },
  "additionalProperties": false
}

When additionalProperties is set to false, the AI will only extract the properties explicitly defined in the schema.

Example Input:

Our Super Widget costs $49.99. It comes in red, blue, and green colors and has a 2-year warranty.

Example Output (with additionalProperties: false):

{
  "name": "Super Widget",
  "price": 49.99
}

Example Output (with additionalProperties: true or not specified):

{
  "name": "Super Widget",
  "price": 49.99,
  "colors": ["red", "blue", "green"],
  "warranty": "2-year"
}

Pro Tip:

Setting additionalProperties to false gives you more control over the exact structure of the extracted data, but you might miss potentially useful information.

Property Naming Patterns

You can use the patternProperties feature to define properties that match a certain pattern.

{
  "type": "object",
  "properties": {
    "name": { 
      "type": "string",
      "description": "The product name"
    }
  },
  "patternProperties": {
    "^dimension_.*": { 
      "type": "number",
      "description": "Product dimensions (width, height, depth, etc.)"
    }
  }
}

Example Input:

The Premium Cabinet has a width of 60cm, height of 120cm, and depth of 45cm.

Example Output:

{
  "name": "Premium Cabinet",
  "dimension_width": 60,
  "dimension_height": 120,
  "dimension_depth": 45
}

Note:

Pattern properties are an advanced feature and implementation may vary depending on the AI model's capabilities.