# Learning JSON File Formats

Two formats exist in production. The **structured** format is newer and preferred.

## Format A — Flat (older, in `continuous-invoice-organizer` learning.json)

```json
{
  "corrections": [],
  "patterns": {
    "rechnung": {
      "amazon_rechnung": {
        "sender": "no-reply@amazon.de",
        "subject_keywords": ["rechnung", "rechnung für"],
        "content_keywords": ["rechnungsnummer", "rechnungsdatum", "rechnungsempfänger", "umsatzsteuer-id", "zahlbetrag"]
      }
    },
    "bestellbestaetigung": {
      "amazon_bestellung": {
        "sender": "bestellbestaetigung@amazon.de",
        "subject_keywords": ["bestellt"],
        "content_keywords": ["bestellnr", "vielen dank fuer deine bestellung"]
      }
    },
    "ignorieren": {
      "amazon_lieferung": {
        "sender": "order-update@amazon.de",
        "subject_keywords": ["zugestellt", "geliefert"]
      }
    }
  },
  "last_scan": "2026-05-19",
  "total_processed": 150,
  "total_moved": 5
}
```

**Used by:** `continuous-invoice-organizer` cronjob (German-language prompts)
**Keys:** `rechnung`, `bestellbestaetigung`, `ignorieren` (German)

## Format B — Structured (newer, in `continuous-email-organization` cronjob prompt)

```json
{
  "corrections": [],
  "patterns": {
    "invoices": {
      "american_express": {
        "sender": "AmericanExpress@welcome.americanexpress.com",
        "subject_pattern": "Online-Monatsabrechnung",
        "folder": "Rechnungen_2026_05"
      }
    },
    "orders": {
      "amazon_de": {
        "sender_pattern": "bestellbestaetigung@amazon.de",
        "subject_pattern": "Bestellt:",
        "folder": "Rechnungen_2026_05/Bestellungen_2026_05"
      }
    },
    "ignore_patterns": {
      "shipment_tracking": "shipment-tracking@amazon.de + In Zustellung → ignoriert"
    },
    "structured_ignore_patterns": [
      {
        "name": "amazon_versand",
        "sender": "versandbestaetigung@amazon.de",
        "subject_keywords": ["versendet", "versand"],
        "notes": "Amazon Versandbestätigung"
      }
    ]
  },
  "last_scan": "2026-05-19",
  "total_processed": 150,
  "total_moved": 5
}
```

**Used by:** `continuous-email-organization` cronjob prompt template
**Keys:** `invoices`, `orders`, `ignore_patterns`, `structured_ignore_patterns`

## Migration note

When merging patterns from both systems:
- `rechnung` (Format A) → maps to `invoices` (Format B)
- `bestellbestaetigung` (Format A) → maps to `orders` (Format B)
- `ignorieren` (Format A) → maps to `structured_ignore_patterns` (Format B)

Always check which format the existing file uses before writing updates.
