louislam/uptime-kuma · warning · Error

Empty or undefined response. Check query syntax and response

Error message

Empty or undefined response. Check query syntax and response structure

What it means

Thrown by evaluateJsonQuery() in src/util.ts when, after applying the JSONata jsonPath to the parsed response, the result is `null` or `undefined`. This is the json-query monitor's strict guard: the configured JSON path must resolve to an actual value before comparison. It exists so a missing field is treated as a monitor failure rather than a silent false-negative.

Source

Thrown at src/util.ts:710

    jsonPath: string,
    jsonPathOperator: string,
    expectedValue: any
): Promise<{ status: boolean; response: any }> {
    // Attempt to parse data as JSON; if unsuccessful, handle based on data type.
    let response: any;
    try {
        response = JSON.parse(data);
    } catch {
        response =
            (typeof data === "object" || typeof data === "number") && !Buffer.isBuffer(data) ? data : data.toString();
    }

    try {
        // If a JSON path is provided, pre-evaluate the data using it.
        response = jsonPath ? await jsonata(jsonPath).evaluate(response) : response;

        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`
            );

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Test the jsonPath against a sample response body with a JSONata playground or `jsonata(path).evaluate(sample)`.
  2. Make the path resilient: use a fallback or pick a field that is always present, or `$lookup` with a default.
  3. Verify the endpoint actually returns the field for the request the monitor sends (auth, params).
  4. If absence should mean DOWN, catch this error and map it to a DOWN status instead of a thrown exception.

Example fix

// before: monitor.jsonPath = "$.status"  but body is { "state": "ok" } -> undefined -> throws

// after: monitor.jsonPath = "$.state"
// or make absence explicit in the path (JSONata):
//   monitor.jsonPath = "($ := $.status; $ ? $ : 'unknown')"
Defensive patterns

Strategy: validation

Validate before calling

const probe = await jsonata(jsonPath).evaluate(sample);
if (probe === null || probe === undefined) throw new Error("Path resolves to nothing on sample");

Type guard

const resolvesToValue = (v) => v !== null && v !== undefined;

Try / catch

try { await evaluateJsonQuery(data, jsonPath, op, expected); } catch (e) { if (/Empty or undefined/.test(e.message)) status = DOWN; else throw e; }

Prevention

When it happens

Trigger: A json-query monitor whose jsonPath selects a field absent from the response (e.g. `$.status` when the body has no such key), a path whose predicate matches nothing (e.g. `$.items[id='999']` returning undefined), a JSONata expression that evaluates to null, or an empty response body where jsonPath still runs. Called from monitor.js:712, snmp.js:63, globalping.js:417.

Common situations: Target API changed its schema and dropped/renamed the field; endpoint returns an error body without the expected field; JSONata path was written against documentation that is out of date; the response is HTML/error page that parsed to a non-object; conditional field that is only present on success.

Related errors


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