JSON Examples

Good

{
    "type": "order",
    "metadata": {
        "id": "f969a06c-5205-4811-9b45-f1baee3ad944",
        "origin": "billing",
        "unix_ts": 1614794613
    },
    "order": {
        "id": "8b034609-7cbe-465f-98a0-6cd1adc72dd9",
        "account_id": "ae59b2f8-832f-4073-ab50-90735d52411d",
        "action": "purchase",
        "unix_ts": 1614794613,
        "products": [
            {
                "id": "c5f03dec-35b0-43fc-9859-1f81a9a89b92", 
                "quantity": 1
            },
            {
                "id": "95e2fb41-8f44-4c96-a74f-4e266ad19a90",
                "quantity": 2
            }
        ]
    }
}

Why is this a good event?

  • Clear indication of event type

  • Utilizes an event envelope that can be used to house other data

  • Low chance for top-level key collisions

  • Clear schema

Bad

{
    "id": "8b034609-7cbe-465f-98a0-6cd1adc72dd9",
    "account_id": "ae59b2f8-832f-4073-ab50-90735d52411d",
    "action": "purchase",
    "unix_ts": 1614794613,
    "products": [
        {
            "id": "c5f03dec-35b0-43fc-9859-1f81a9a89b92", 
            "quantity": 1
        },
        {
            "id": "95e2fb41-8f44-4c96-a74f-4e266ad19a90",
            "quantity": 2
        }
    ]
}

Why is this a bad event?

  • No clear indication of event type

  • High chance of top-level key collisions

  • Ambiguous field names such as "id" and "action"

  • Fields are re-used between different events

  • Unclear schema

Last updated