<!--
title: Match defaults to types
domain: app-frameworks
topic: Null Handling
language: Json
source: appwrite/appwrite
updated: 2025-05-18
url: https://awesomereviewers.com/reviewers/appwrite-match-defaults-to-types/
-->

When specifying default values in schemas or configurations, ensure they match the declared type to prevent validation errors and unpredictable behavior. For object types, use empty objects (`{}`) not null, undefined, or arrays. For string types that should be empty by default, use empty strings (`""`) not null. This practice improves type safety and prevents runtime type errors.

```diff
// INCORRECT: Type mismatch between declared type and default
{
  "type": "object",
  "description": "Document data as JSON object.",
  "default": [],  // An array default for an object type
}

// CORRECT: Type-consistent defaults
{
  "type": "object",
  "description": "Document data as JSON object.",
  "default": {},  // An object default for an object type
}

// CORRECT: Empty string default for optional string
{
  "type": "string",
  "description": "Optional document ID",
  "default": "",  // Empty string instead of null
}
```
