Prompt

How do I compare expected vs actual API responses across many cases?

Technology / Testing & QA1 observationLast seen Oct 6, 2026

Latest observation

Oct 6, 2026OpenAI APIWeb search: off

A good way to compare expected vs actual API responses across many cases is to make the comparison structured, automated, and diff-friendly.

Practical approach

1. Define a canonical shape for responses

Don’t compare raw JSON strings. Instead:

  • parse responses into objects
  • normalize volatile fields like:
    • timestamps
    • IDs
    • ordering of arrays if order doesn’t matter
    • null vs missing fields, if relevant

2. Store test cases in a table or fixture file

For each case, keep:

  • request input
  • expected response
  • actual response
  • comparison result
  • diff / mismatched fields

Example schema:

case_idrequestexpectedactualpass
1.........true
2.........false

3. Compare field-by-field

Use a deep comparison that can:

  • check exact matches for strict fields
  • allow fuzzy matching for:
    • timestamps
    • numeric tolerances
    • subsets of arrays/objects
  • report path-level differences like:
    • data.user.name
    • items[2].price

4. Produce a summary and diffs

For many cases, the most useful output is:

  • total passed / failed
  • list of failed case IDs
  • exact mismatched fields
  • optional JSON diff for each failure

5. Automate with tests

This is easiest in:

  • pytest / unittest for Python
  • Jest / Mocha for JS
  • Postman/Newman for API collections
  • Pact if you need contract testing

Example in Python

import json
from deepdiff import DeepDiff

def normalize(resp):
    resp = dict(resp)
    resp.pop("timestamp", None)
    resp.pop("request_id", None)
    return resp

cases = [
    {"id": 1, "expected": {"a": 1, "timestamp": "x"}, "actual": {"a": 1, "timestamp": "y"}},
    {"id": 2, "expected": {"b": 2}, "actual": {"b": 3}},
]

for case in cases:
    exp = normalize(case["expected"])
    act = normalize(case["actual"])
    diff = DeepDiff(exp, act, ignore_order=True)

    if diff:
        print(f"FAIL case {case['id']}: {diff}")
    else:
        print(f"PASS case {case['id']}")

If you have lots of cases

Use one of these patterns:

  • CSV/Excel + script for simple validation
  • JSON/YAML fixtures + test runner for maintainability
  • database-backed results if you need dashboards/history
  • snapshot testing if responses are stable and large

Best practices

  • Compare semantic equality, not raw text
  • Normalize unstable fields
  • Make failures readable
  • Keep expected results versioned in source control
  • Separate strict assertions from tolerant ones

If you want, I can show you:

  1. a Python script to compare hundreds of cases,
  2. a JavaScript/Jest version, or
  3. a CSV/Excel-based workflow.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as Circuit. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.