Data Types
This section covers the core JSON data types supported by dotjson. Use it as a concept reference; keyword-level constraints live in the Constraints guide.
Type Overview
The type of a value in dotjson is specified using the type keyword. The basic types are:
string- Text datanumber- Any numeric value (integer or decimal)integer- Whole numbers onlyboolean- True or false valuesnull- Null valuesarrayandobject- See the Structures guide for details
String
Strings represent text data.
Basic String
{"type": "string"}For string length, pattern, or format constraints, see the Constraints guide.
Number & Integer
Numeric types handle mathematical values with optional range constraints.
Difference Between Number and Integer
integer- Whole numbers only (e.g., -2, 0, 42)number- Any numeric value including decimals (e.g., 3.14, -0.5, 42)
For numeric ranges like minimum/maximum, see Constraints.
Boolean
Boolean values represent binary choices - true or false. They’re ideal for flags, switches, and binary classifications.
Simple Boolean Field
{
"type": "object",
"properties": {
"isActive": {
"type": "boolean",
"description": "Whether the account is active"
},
"hasDiscount": {
"type": "boolean",
"description": "Whether a discount applies"
},
"requiresShipping": {
"type": "boolean",
"description": "Whether physical shipping is needed"
}
},
"required": ["isActive"]
}{
"isActive": true,
"hasDiscount": false,
"requiresShipping": true
}Boolean for Classification
Booleans are particularly useful for binary classification tasks:
{
"type": "object",
"properties": {
"isSpam": {
"type": "boolean",
"description": "Whether the message is spam"
},
"isUrgent": {
"type": "boolean",
"description": "Whether immediate action is required"
},
"containsPii": {
"type": "boolean",
"description": "Whether personally identifiable information is present"
}
},
"required": ["isSpam", "isUrgent", "containsPii"]
}{
"isSpam": false,
"isUrgent": true,
"containsPii": false
}Null
The null type represents a null value. Use it in combination with other types (for example via anyOf) to make a field nullable. Optionality is separate: a field is optional if it is not listed in required.
Basic Null Type
{
"type": "object",
"properties": {
"placeholder": {
"type": "null",
"description": "Always null"
}
},
"required": ["placeholder"]
}{
"placeholder": null
}Nullable Fields
Combine null with other types using anyOf to allow a field to be present with a null value (nullable). The field remains required if listed in required.
{
"type": "object",
"properties": {
"middleName": {
"anyOf": [
{"type": "string"},
{"type": "null"}
],
"description": "Optional middle name"
},
"alternateEmail": {
"anyOf": [
{"type": "string", "format": "email"},
{"type": "null"}
],
"default": null,
"description": "Optional alternate email"
}
},
"required": ["middleName", "alternateEmail"]
}With values:
{
"middleName": "James",
"alternateEmail": "[email protected]"
}Without values:
{
"middleName": null,
"alternateEmail": null
}Note
Optional fields: omit the field name from the required array to allow it to be omitted entirely.
Next Steps
- Learn about Structures to work with objects and arrays.
- Explore Constraints for advanced options.
- See Practical Examples for real-world applications.