Query json directly rather than with $.value

-This is less abstract
-Maximum compatibility with @chakflying's existing json-query monitor code.
This commit is contained in:
Matt Visnovsky
2024-06-06 10:08:07 -06:00
parent 36dc94b8f2
commit 10d3188dd3
2 changed files with 11 additions and 5 deletions

View File

@@ -427,10 +427,16 @@ async function evaluateJsonQuery(data, jsonPath, jsonPathOperator, expectedValue
throw new Error(`Invalid condition ${jsonPathOperator}`);
}
const expression = jsonata(jsonQueryExpression);
const evaluation = await expression.evaluate({
value: response,
control: expected
});
let evaluation;
if (jsonPathOperator === "custom") {
evaluation = await expression.evaluate(response);
}
else {
evaluation = await expression.evaluate({
value: response,
control: expectedValue
});
}
if (evaluation === undefined) {
throw new Error("Query evaluation returned undefined. Check your query syntax and the structure of the response data.");
}