YAML Schema Number and Integer Types from JSON

Learn how JSON numeric values map to YAML Schema integer and number types. Covers minimum, maximum, multipleOf, exclusiveMinimum, and the distinction between integer and number.

Type Mapping

Detailed Explanation

Number Type Mapping in YAML Schema

JSON has a single number type, but YAML Schema distinguishes between integer (whole numbers) and number (any numeric value including decimals). The converter infers the appropriate type from the JSON value.

Type Inference Rules

JSON value YAML Schema type
42 integer
3.14 number
0 integer
-17.5 number
1.0 number (has decimal point)

Example JSON Input

{
  "port": 8080,
  "maxConnections": 100,
  "timeout": 30.5,
  "retryFactor": 1.5
}

Generated YAML Schema

type: object
properties:
  port:
    type: integer
    minimum: 1
    maximum: 65535
  maxConnections:
    type: integer
    minimum: 1
  timeout:
    type: number
    minimum: 0
  retryFactor:
    type: number
    exclusiveMinimum: 0

Numeric Constraints

Constraint Purpose Example
minimum Minimum value (inclusive) minimum: 0
maximum Maximum value (inclusive) maximum: 65535
exclusiveMinimum Minimum value (exclusive) exclusiveMinimum: 0
exclusiveMaximum Maximum value (exclusive) exclusiveMaximum: 100
multipleOf Value must be divisible by multipleOf: 5

Port Number Validation

A common pattern for network configuration:

port:
  type: integer
  minimum: 1
  maximum: 65535
  description: TCP port number

Percentage Fields

cpuThreshold:
  type: number
  minimum: 0
  maximum: 100
  description: CPU usage percentage

multipleOf for Step Values

interval:
  type: integer
  minimum: 5
  multipleOf: 5
  description: Polling interval in seconds (must be multiple of 5)

Integer vs Number Decision

Use integer when the value must be a whole number (counts, IDs, port numbers). Use number when decimal precision is needed (percentages, rates, coordinates). Choosing the correct type improves validation accuracy -- a port number of 8080.5 would correctly fail validation with type: integer.

Use Case

Infrastructure configuration often involves numeric parameters with strict ranges -- port numbers between 1 and 65535, timeout values that must be positive, retry counts that must be integers. A YAML schema with numeric constraints prevents misconfiguration that could cause service outages or resource exhaustion.

Try It — JSON to YAML Schema

Open full tool