louislam/uptime-kuma · warning · Error

The post-JSON query evaluated response from the server is of

Error message

The post-JSON query evaluated response from the server is of type ${typeof response}, which cannot be directly compared to the expected value

What it means

Thrown by evaluateJsonQuery() when the post-JSONata response is a non-array object, a Date instance, or a function. The comparator built later in the function only handles primitives (numbers, strings, booleans), so a structured object cannot be meaningfully compared to expectedValue and is rejected up front.

Source

Thrown at src/util.ts:726

        if (response === null || response === undefined) {
            throw new Error("Empty or undefined response. Check query syntax and response structure");
        }

        // Check for arrays: JSONata filter expressions like .[predicate] always return arrays
        if (Array.isArray(response)) {
            const responseStr = JSON.stringify(response);
            const truncatedResponse = responseStr.length > 25 ? responseStr.substring(0, 25) + "...]" : responseStr;
            throw new Error(
                "JSON query returned the array " +
                    truncatedResponse +
                    ", but a primitive value is required. " +
                    "Modify your query to return a single value via [0] to get the first element or use an aggregation like $count(), $sum() or $boolean()."
            );
        }

        if (typeof response === "object" || response instanceof Date || typeof response === "function") {
            throw new Error(
                `The post-JSON query evaluated response from the server is of type ${typeof response}, which cannot be directly compared to the expected value`
            );
        }

        // Perform the comparison logic using the chosen operator
        let jsonQueryExpression;
        switch (jsonPathOperator) {
            case ">":
            case ">=":
            case "<":
            case "<=":
                jsonQueryExpression = `$number($.value) ${jsonPathOperator} $number($.expected)`;
                break;
            case "!=":
                jsonQueryExpression = "$.value != $.expected";
                break;
            case "==":
                jsonQueryExpression = "$.value = $.expected";

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Drill the path down to a primitive leaf: `$.user.email`, `$.metadata.version`, `$.data.payload.count`.
  2. If you need to compare a sub-property, project it with JSONata: `$.user.{ 'email': email }` is still an object — instead use `$.user.email`.
  3. Confirm the field's type in a sample response; choose a scalar field for the comparison.
  4. If the whole object matters, encode it as a string first (e.g. `$string($.user)`) and use the contains operator.

Example fix

// before: monitor.jsonPath = "$.user"  -> object -> throws

// after: select a primitive leaf
//   monitor.jsonPath = "$.user.email"
//   operator "==", expectedValue "alice@example.com"
Defensive patterns

Strategy: validation

Validate before calling

const probe = await jsonata(jsonPath).evaluate(sample);
if (probe !== null && probe !== undefined && typeof probe === "object") throw new Error("Path returns an object; select a leaf");

Type guard

const isLeafPrimitive = (v) => v === null || v === undefined || ["string","number","boolean"].includes(typeof v);

Try / catch

try { await evaluateJsonQuery(data, path, op, expected); } catch (e) { if (/is of type object/.test(e.message)) { path += ".<leaf>"; /* drill */ } else throw e; }

Prevention

When it happens

Trigger: monitor.jsonPath selects a nested object node rather than a leaf: `$.user` where user is an object, `$.metadata`, `$.data.payload`. Also a JSONata expression that constructs an object (e.g. `{ id, name }`). Dates arise when a path selects a field JSONata parses as a Date.

Common situations: User points the path at a container object instead of a scalar field; schema change promoted a scalar to an object; path copied from a hierarchical example without drilling to a leaf; expectedValue configured against a property of an object rather than the object itself.

Related errors


AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12). Data as JSON: /api/errors/018720e3fe4c6e4b. Report an issue: GitHub.