Your nested JSON condition issue has three root causes that need to be addressed together:
Rule Condition Syntax:
The oiot-23 rules engine doesn’t support standard dot notation for nested object traversal beyond the first level. You must use JSONPath syntax for any nested properties:
{
"condition": "$.payload.sensor.temperature > 75",
"conditionType": "JSONPATH",
"action": "sendAlert"
}
The $ prefix indicates JSONPath mode, and you must explicitly set conditionType to JSONPATH in your rule configuration. Without this, the engine defaults to simple expression evaluation which only handles flat structures.
Alternatively, use bracket notation with the EXPRESSION type:
{
"condition": "event['payload']['sensor']['temperature'] > 75",
"conditionType": "EXPRESSION"
}
Both syntaxes work, but JSONPath is more robust for complex nested structures.
Nested JSON Parsing:
The rules engine requires explicit type definitions for nested objects. When using nested paths, you must register a detailed event schema that includes all levels:
{
"eventType": "sensorReading",
"schema": {
"deviceId": {"type": "string"},
"payload": {
"type": "object",
"properties": {
"sensor": {
"type": "object",
"properties": {
"temperature": {"type": "number"},
"unit": {"type": "string"}
}
}
}
}
}
}
Register this schema via the API SDK before creating rules:
EventSchema schema = new EventSchema();
schema.setEventType("sensorReading");
schema.setSchema(schemaDefinition);
rulesClient.registerSchema(schema);
Without a properly registered schema, the parser doesn’t know how to interpret nested structures and fails silently.
Event Schema Validation:
The rules engine performs strict schema validation before condition evaluation. Even if your events are being stored correctly, they might be failing rule-specific validation. Enable validation logging:
RuleConfig config = new RuleConfig();
config.setValidationMode("STRICT");
config.setLogValidationErrors(true);
This exposes validation failures that are otherwise hidden. Common issues include:
- Type mismatches (string vs number)
- Missing required nested properties
- Schema version conflicts
Also ensure your event payloads match the schema exactly. The temperature value must be a numeric type, not a string:
{"temperature": 82} // Correct
{"temperature": "82"} // Wrong - will fail validation
Implement these three fixes together: use JSONPath syntax, register detailed nested schemas, and enable validation logging. Your nested condition rules should then trigger reliably.