JSON

Last updated on October 28, 2026

WiFi Enabled
True
x==True
PASS
Operating Mode
PASS
{
"mode": "active",
"power": "high"
}
Output Voltage
5.02
4.8<x<5.2
PASS
JSON Measurement: Operating Mode
  Value: { "mode": "active", "power": "high" }
  Validator: x == { "mode": "active", "power": "high" }
  Outcome: PASS

You can create a JSON measurement with measurements:

measurements:
  - name: Operating Mode
    validators: 
      - operator: "=="
        expected_value: 
          mode: active
          power: high

You 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.

PropertyTypeRequiredDescription
keystringNoUnique identifier for the measurement within the phase
namestringYesDisplay name (1-100 characters)
unitstringNoMeasurement unit (max 50 characters)
descriptionstringNoDetailed 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:

PropertyTypeRequiredDescription
operatorstringYesComparison operator
expected_valueobject or arrayYesExpected 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:

OperatorExpected ValueDescriptionExample
==Object or arrayValue must equal expectedexpected_value: { "mode": "active" }
!=Object or arrayValue must not equal expectedexpected_value: {}
inArray of valuesValue must be one of the allowed valuesexpected_value: [{ "mode": "active" }, { "mode": "idle" }]
not inArray of valuesValue must not be one of the valuesexpected_value: [{ "mode": "error" }]

TofuPilot evaluates validators and sets the outcome to PASS if met, FAIL if not, or if no value was provided, and PASS if there are no validators, as in OpenHTF. See Outcome.

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:

name: Device Configuration Test

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: high
def 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:

name: Camera Module Test

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 device
def capture_config(log, measurements, device):
    log.info("Reading device configuration")

    measurements.device_config = device.dump_config()

How is this guide?

On this page