JSON similarity
JSON similarity computes a recursive structural similarity between the output JSON and the expected JSON, field by field, with partial credit for close numbers and strings. It mirrors UiPath's JsonSimilarityEvaluator and autoevals JSONDiff and is free.
Runs in code, free. Mirrors uipath.eval JsonSimilarityEvaluator / autoevals JSONDiff
What the evaluator does
Parse both; for objects average over the union of keys, for arrays average position-wise, numbers by relative difference, strings by normalised edit distance. Score 0–1; pass at 0.9.
{"invoice_no":"INV-2231",
"total":1849.5,
"currency":"USD"}{"invoice_no":"INV-2231",
"total":1849.50,
"currency":"USD",
"due":"2026-10-15"}When to use it
Reach for it when
- Structured extraction (invoices, forms, entities).
- Tool-call argument objects where exact equality is too strict but semantic judgment is overkill.
Not the right tool when
- Key names differ legitimately (use tool_call_semantic or llm_judge).
- Either side is not valid JSON (score is 0).
Watch out for
- Extra keys in the output reduce the score; decide whether that is desired.
- Array order matters.
What to send
score 0–1 computed in code, label, passed at an evaluator-specific threshold, no probabilities.
{
"evaluators": [
"json_similarity"
],
"output": "{\"invoice_no\":\"INV-2231\",\"total\":1849.5,\"currency\":\"USD\"}",
"expected": "{\"invoice_no\":\"INV-2231\",\"total\":1849.50,\"currency\":\"USD\",\"due\":\"2026-10-15\"}"
}Three of four fields match exactly: 0.75.
Aggregate with
One result per item is a fact; a dataset of them is a metric. These are the aggregations that fit this evaluator's output shape.
Related evaluators
Questions people ask
- How does JSON similarity score numbers?
- By relative difference: 1849.5 vs 1849.50 is identical; 100 vs 110 scores 0.9.