JSON
Last updated on June 16, 2026
JSON Measurement: Operating Mode
Value: { "mode": "active", "power": "high" }
Validator: x == { "mode": "active", "power": "high" }
Outcome: PASSYou can create a JSON measurement with measurements:
measurements:
- name: Operating Mode
validators:
- operator: "=="
expected_value:
mode: active
power: highYou can set the measurement value in your Python phase by assigning a dict or list:
def check_mode(measurements):
measurements.operating_mode = {"mode": "active", "power": "high"} TofuPilot detects the JSON type from the value. Any dict, or any list that is not a numeric matrix, is stored as a JSON measurement. A numeric matrix (a list of equal-length numeric lists) is stored as a multi-dimensional measurement instead.
Definition
You can configure the measurement name and metadata.
| Property | Type | Required | Description |
|---|---|---|---|
key | string | No | Unique identifier for the measurement within the phase |
name | string | Yes | Display name (1-100 characters) |
unit | string | No | Measurement unit (max 50 characters) |
description | string | No | Detailed description (max 50,000 characters) |
TofuPilot auto-generates the key from name (snake_case) if not specified, and uses it for Python access (e.g., measurements.operating_mode). The unit and description display in the web interface and reports.
Validators
You can add one or several validators to your measurement using the following properties:
| Property | Type | Required | Description |
|---|---|---|---|
operator | string | Yes | Comparison operator |
expected_value | object or array | Yes | Expected JSON value for comparison |
A JSON object has no single comparable scalar, so JSON measurements compare the whole value. You can use the following operators for JSON measurements:
| Operator | Expected Value | Description | Example |
|---|---|---|---|
== | Object or array | Value must equal expected | expected_value: { "mode": "active" } |
!= | Object or array | Value must not equal expected | expected_value: {} |
in | Array of values | Value must be one of the allowed values | expected_value: [{ "mode": "active" }, { "mode": "idle" }] |
not in | Array of values | Value must not be one of the values | expected_value: [{ "mode": "error" }] |
TofuPilot evaluates validators and sets the outcome to PASS if met, FAIL if not, or UNSET if no value provided.
To validate a single field, extract it in your Python phase and record it as a typed numeric, string, or boolean measurement.
Examples
Mode Check
We will read the device mode object and verify it matches the expected configuration:
main:
- name: Mode Check
python: phases.check_mode
measurements:
- name: Operating Mode
description: Active operating mode reported by the device
validators:
- operator: "=="
expected_value:
mode: active
power: highdef check_mode(log, measurements):
log.info("Reading operating mode")
measurements.operating_mode = {
"mode": "active",
"power": "high",
}Configuration Snapshot
We will capture the full device configuration for traceability, with no validation:
plugs:
- key: device
name: Device
python: plugs.device:Device
main:
- name: Capture Config
python: phases.capture_config
measurements:
- name: Device Config
description: Full configuration snapshot read from the devicedef capture_config(log, measurements, device):
log.info("Reading device configuration")
measurements.device_config = device.dump_config()How is this guide?