{"record":{"id":"018720e3fe4c6e4b","repo":"louislam/uptime-kuma","slug":"the-post-json-query-evaluated-response-from-the-se","errorCode":null,"errorMessage":"The post-JSON query evaluated response from the server is of type ${typeof response}, which cannot be directly compared to the expected value","messagePattern":"The post-JSON query evaluated response from the server is of type (.+?), which cannot be directly compared to the expected value","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/util.ts","lineNumber":726,"sourceCode":"\n        if (response === null || response === undefined) {\n            throw new Error(\"Empty or undefined response. Check query syntax and response structure\");\n        }\n\n        // Check for arrays: JSONata filter expressions like .[predicate] always return arrays\n        if (Array.isArray(response)) {\n            const responseStr = JSON.stringify(response);\n            const truncatedResponse = responseStr.length > 25 ? responseStr.substring(0, 25) + \"...]\" : responseStr;\n            throw new Error(\n                \"JSON query returned the array \" +\n                    truncatedResponse +\n                    \", but a primitive value is required. \" +\n                    \"Modify your query to return a single value via [0] to get the first element or use an aggregation like $count(), $sum() or $boolean().\"\n            );\n        }\n\n        if (typeof response === \"object\" || response instanceof Date || typeof response === \"function\") {\n            throw new Error(\n                `The post-JSON query evaluated response from the server is of type ${typeof response}, which cannot be directly compared to the expected value`\n            );\n        }\n\n        // Perform the comparison logic using the chosen operator\n        let jsonQueryExpression;\n        switch (jsonPathOperator) {\n            case \">\":\n            case \">=\":\n            case \"<\":\n            case \"<=\":\n                jsonQueryExpression = `$number($.value) ${jsonPathOperator} $number($.expected)`;\n                break;\n            case \"!=\":\n                jsonQueryExpression = \"$.value != $.expected\";\n                break;\n            case \"==\":\n                jsonQueryExpression = \"$.value = $.expected\";","sourceCodeStart":708,"sourceCodeEnd":744,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/src/util.ts#L708-L744","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Drill the path down to a primitive leaf: `$.user.email`, `$.metadata.version`, `$.data.payload.count`.","If you need to compare a sub-property, project it with JSONata: `$.user.{ 'email': email }` is still an object — instead use `$.user.email`.","Confirm the field's type in a sample response; choose a scalar field for the comparison.","If the whole object matters, encode it as a string first (e.g. `$string($.user)`) and use the contains operator."],"exampleFix":"// before: monitor.jsonPath = \"$.user\"  -> object -> throws\n\n// after: select a primitive leaf\n//   monitor.jsonPath = \"$.user.email\"\n//   operator \"==\", expectedValue \"alice@example.com\"","handlingStrategy":"validation","validationCode":"const probe = await jsonata(jsonPath).evaluate(sample);\nif (probe !== null && probe !== undefined && typeof probe === \"object\") throw new Error(\"Path returns an object; select a leaf\");","typeGuard":"const isLeafPrimitive = (v) => v === null || v === undefined || [\"string\",\"number\",\"boolean\"].includes(typeof v);","tryCatchPattern":"try { await evaluateJsonQuery(data, path, op, expected); } catch (e) { if (/is of type object/.test(e.message)) { path += \".<leaf>\"; /* drill */ } else throw e; }","preventionTips":["Drill paths to scalar leaves.","Map expectedValue to the specific field you compare.","Use $string(...) + contains for whole-object checks."],"tags":["json-query","jsonata","monitor","validation","typescript","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}