Skip to content

JSON Schema Basics

TinySystems uses JSON Schema to define port data structures. The SDK generates schemas automatically from Go structs, but understanding the underlying schema format helps when building complex components.

What is JSON Schema?

JSON Schema is a vocabulary for annotating and validating JSON documents. In TinySystems, schemas serve multiple purposes:

  • UI Generation: The visual editor renders forms based on schemas
  • Validation: Incoming data is validated against schemas
  • Documentation: Schemas describe expected data formats
  • Type Safety: Ensures data flows correctly between components

Schema Structure

A typical JSON Schema:

json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "title": "HTTP Request",
  "description": "An HTTP request configuration",
  "properties": {
    "method": {
      "type": "string",
      "title": "HTTP Method",
      "enum": ["GET", "POST", "PUT", "DELETE"],
      "default": "GET"
    },
    "url": {
      "type": "string",
      "title": "URL",
      "format": "uri"
    },
    "body": {
      "title": "Request Body"
    }
  },
  "required": ["url"]
}

Basic Types

String

json
{
  "type": "string",
  "title": "Name",
  "description": "Enter your name",
  "minLength": 1,
  "maxLength": 100,
  "default": ""
}

Go equivalent:

go
Name string `json:"name" title:"Name" description:"Enter your name" minLength:"1" maxLength:"100"`

Number

json
{
  "type": "number",
  "title": "Amount",
  "minimum": 0,
  "maximum": 1000,
  "default": 100
}

Go equivalent:

go
Amount float64 `json:"amount" title:"Amount" minimum:"0" maximum:"1000" default:"100"`

Integer

json
{
  "type": "integer",
  "title": "Count",
  "minimum": 1,
  "maximum": 100
}

Go equivalent:

go
Count int `json:"count" title:"Count" minimum:"1" maximum:"100"`

Boolean

json
{
  "type": "boolean",
  "title": "Enabled",
  "default": true
}

Go equivalent:

go
Enabled bool `json:"enabled" title:"Enabled" default:"true"`

Array

json
{
  "type": "array",
  "title": "Items",
  "items": {
    "type": "string"
  },
  "minItems": 1,
  "maxItems": 10
}

Go equivalent:

go
Items []string `json:"items" title:"Items" minItems:"1" maxItems:"10"`

Object

json
{
  "type": "object",
  "title": "Configuration",
  "properties": {
    "host": {"type": "string"},
    "port": {"type": "integer"}
  }
}

Go equivalent:

go
type Config struct {
    Host string `json:"host"`
    Port int    `json:"port"`
}

Schema Keywords

Validation Keywords

KeywordTypeDescription
typeAllData type (string, number, integer, boolean, array, object)
enumAllList of allowed values
constAllSingle allowed value
defaultAllDefault value

String Keywords

KeywordDescription
minLengthMinimum string length
maxLengthMaximum string length
patternRegex pattern
formatSemantic validation (email, uri, etc.)

Number Keywords

KeywordDescription
minimumMinimum value (inclusive)
maximumMaximum value (inclusive)
exclusiveMinimumMinimum value (exclusive)
exclusiveMaximumMaximum value (exclusive)
multipleOfValue must be multiple of

Array Keywords

KeywordDescription
itemsSchema for array items
minItemsMinimum array length
maxItemsMaximum array length
uniqueItemsAll items must be unique

Object Keywords

KeywordDescription
propertiesProperty schemas
requiredList of required properties
additionalPropertiesSchema for extra properties

Format Strings

The format keyword provides semantic validation:

FormatDescriptionExample
emailEmail addressuser@example.com
uriFull URIhttps://example.com
uri-referenceURI or relative reference/path/to/resource
dateISO 8601 date2024-01-15
date-timeISO 8601 datetime2024-01-15T10:30:00Z
timeISO 8601 time10:30:00
durationISO 8601 durationP1D (1 day)
ipv4IPv4 address192.168.1.1
ipv6IPv6 address::1
uuidUUID550e8400-e29b-41d4-a716-446655440000
passwordMasked input (UI hint)*****
buttonButton in UIN/A

Enum Values

Define allowed values:

json
{
  "type": "string",
  "title": "Log Level",
  "enum": ["debug", "info", "warn", "error"],
  "default": "info"
}

With display titles:

go
Level string `json:"level" title:"Log Level" enum:"debug,info,warn,error" enumTitles:"Debug,Info,Warning,Error"`

Required Fields

Mark fields as required:

json
{
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "email": {"type": "string"}
  },
  "required": ["name", "email"]
}

Go equivalent:

go
Name  string `json:"name" required:"true"`
Email string `json:"email" required:"true"`

Nested Objects

json
{
  "type": "object",
  "properties": {
    "server": {
      "type": "object",
      "title": "Server Settings",
      "properties": {
        "host": {"type": "string"},
        "port": {"type": "integer"}
      }
    },
    "auth": {
      "type": "object",
      "title": "Authentication",
      "properties": {
        "username": {"type": "string"},
        "password": {"type": "string", "format": "password"}
      }
    }
  }
}

Go equivalent:

go
type Settings struct {
    Server ServerConfig `json:"server" title:"Server Settings"`
    Auth   AuthConfig   `json:"auth" title:"Authentication"`
}

type ServerConfig struct {
    Host string `json:"host"`
    Port int    `json:"port"`
}

type AuthConfig struct {
    Username string `json:"username"`
    Password string `json:"password" format:"password"`
}

Arrays of Objects

json
{
  "type": "array",
  "title": "Endpoints",
  "items": {
    "type": "object",
    "properties": {
      "name": {"type": "string"},
      "url": {"type": "string", "format": "uri"}
    },
    "required": ["name", "url"]
  }
}

Go equivalent:

go
type Settings struct {
    Endpoints []Endpoint `json:"endpoints" title:"Endpoints"`
}

type Endpoint struct {
    Name string `json:"name" required:"true"`
    URL  string `json:"url" format:"uri" required:"true"`
}

Any Type

For flexible data:

json
{
  "title": "Data",
  "description": "Any JSON value"
}

Go equivalent:

go
Data any `json:"data" title:"Data" description:"Any JSON value"`

UI Hints

Additional tags for the visual editor:

TagDescription
propertyOrderField display order
widgetCustom widget (textarea, code, etc.)
readOnlyField is read-only
hiddenHide from UI

Example:

go
type Settings struct {
    Name    string `json:"name" propertyOrder:"1"`
    Code    string `json:"code" propertyOrder:"2" widget:"code"`
    Details string `json:"details" propertyOrder:"3" widget:"textarea"`
}

Next Steps

Build flow-based applications on Kubernetes