Prompt

How do I normalize messy JSON logs from different services?

Technology / Observability1 observationLast seen Oct 27, 2026

Latest observation

Oct 27, 2026OpenAI APIWeb search: off

To normalize messy JSON logs from different services, aim to convert all events into a single canonical schema before indexing, querying, or storing them.

1) Define a canonical log shape

Pick a standard set of fields that every log should map into, for example:

{
  "timestamp": "",
  "service": "",
  "environment": "",
  "level": "",
  "message": "",
  "trace_id": "",
  "span_id": "",
  "request_id": "",
  "user_id": "",
  "event_type": "",
  "source": "",
  "raw": {}
}

Keep:

  • required fields: timestamp, service, level, message
  • correlation fields: trace_id, span_id, request_id
  • context fields: user_id, environment, event_type
  • raw: the original payload for debugging/auditing

2) Build a field-mapping layer

Different services often use different names for the same concept.

Examples:

  • ts, time, datetime → timestamp
  • severity, log_level → level
  • msg, message, event.message → message
  • service_name, app, component → service

Create a mapping table per service or use a shared ruleset.

3) Handle nested and inconsistent structures

Logs may be deeply nested or inconsistently shaped.

Example inputs:

{ "ts": "2026-10-27T12:00:00Z", "severity": "INFO", "msg": "started" }
{ "timestamp": 1698408000, "level": "info", "message": "started", "meta": { "service": "api" } }

Normalize by:

  • flattening nested fields
  • extracting known keys
  • preserving unknown fields in raw or attributes

4) Standardize types and formats

Convert values into consistent types:

  • timestamps → ISO 8601 UTC
  • log level → uppercase or lowercase consistently
  • IDs → strings
  • booleans/numbers → typed values, not strings

Example:

  • 1698408000 → "2026-10-27T12:00:00Z"
  • "INFO" and "info" → "info"

5) Add defaults and validation

Not every record will be complete. Apply defaults:

  • missing service → "unknown"
  • missing level → "info"
  • missing message → empty string or derived from event fields

Validate output against your schema and reject or quarantine invalid records.

6) Preserve original data

Don’t throw away the original payload. Store it in:

  • raw
  • original_event
  • or a dead-letter queue if parsing fails

This is essential for debugging normalization errors.

7) Use a processing pipeline

A typical pipeline looks like:

  1. ingest raw logs
  2. parse JSON
  3. detect service/source
  4. map fields to canonical schema
  5. transform types/normalize values
  6. validate
  7. enrich with metadata
  8. emit/store normalized event

8) Add enrichment if useful

You can enrich logs with:

  • deployment version
  • region/cluster
  • host/pod/container info
  • environment
  • customer/tenant ID

This makes cross-service analysis much easier.

9) Example transformation

Input:

{
  "ts": "2026/10/27 12:00:00",
  "sev": "warn",
  "text": "cache miss",
  "svc": "payment-api",
  "requestId": 12345,
  "extra": { "user": "alice" }
}

Normalized:

{
  "timestamp": "2026-10-27T12:00:00Z",
  "service": "payment-api",
  "level": "warn",
  "message": "cache miss",
  "request_id": "12345",
  "user_id": "alice",
  "raw": {
    "ts": "2026/10/27 12:00:00",
    "sev": "warn",
    "text": "cache miss",
    "svc": "payment-api",
    "requestId": 12345,
    "extra": { "user": "alice" }
  }
}

10) Tools that help

Depending on your stack:

  • Logstash / Fluent Bit / Vector for ingestion and transformation
  • jq for ad hoc JSON reshaping
  • Python / Go for custom normalization
  • OpenTelemetry Logs for standardized telemetry fields
  • JSON Schema / Pydantic / Zod for validation

Practical recommendation

If you’re starting from scratch:

  • create a canonical schema
  • implement service-specific mappers
  • preserve raw data
  • validate everything
  • add correlation IDs consistently

If you want, I can also give you:

  1. a Python normalization example,
  2. a jq recipe, or
  3. a JSON Schema for normalized logs.

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 dotdotPR. 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.