Der Parser folgt der CSV-Konvention korrekt, statt an Kommas zu trennen: Ein in Anführungszeichen gesetztes Feld darf das Trennzeichen, Zeilenumbrüche und doppelte Anführungszeichen enthalten, und alle drei überstehen es. Dieser Unterschied ist der Grund, warum ein naives Trennen schon am ersten Adressfeld scheitert, und die mit Abstand häufigste Ursache dafür, dass eine CSV-Umwandlung die falsche Spaltenzahl liefert.
Das Trennzeichen wird ermittelt, indem Komma, Semikolon, Tabulator und Senkrechtstrich ausprobiert, die ersten Zeilen mit jedem geparst und dasjenige behalten wird, das die gleichmäßigste Spaltenzahl ergibt — das erledigt die europäische Semikolon-Konvention, ohne zu fragen. Werte lassen sich in ihren Typ überführen, Zahlen und Wahrheitswerte kommen dann als Zahlen und Wahrheitswerte an statt als Zeichenketten, und ein Feld in Anführungszeichen bleibt eine Zeichenkette, weil die Anführungszeichen eine Absichtserklärung waren.
Wo CSV-Dateien schiefgehen
-
Ein nicht geschlossenes Anführungszeichen verschluckt den Rest der Datei:
Der Parser meldet das, statt still zu scheitern, denn sonst ist das einzige Symptom ein einziger riesiger letzter Wert ohne erkennbare Ursache.
-
Führende Nullen sind das klassische Opfer der Typumwandlung:
Eine Postleitzahl oder eine Kennung wie 01234 wird als Zahl zu 1234. Setzen Sie solche Felder in der Quelle in Anführungszeichen oder schalten Sie die Umwandlung ab.
-
Gleichnamige Spaltenüberschriften kollidieren:
Zwei Spalten mit demselben Namen ergeben einen Schlüssel in der Ausgabe. Benennen Sie sie vor der Umwandlung in der Quelle um.
-
CSV kennt keine Kodierungsangabe:
Eine als Latin-1 gespeicherte und als UTF-8 gelesene Datei liefert entstellte Akzente, und nichts im Format sagt, welche es ist. Beheben Sie das beim Export.
Why a naive comma split fails on the first address field
A properly quoted CSV field can legally contain the delimiter, a line break, and doubled quote marks, and all three have to survive intact through the conversion. The [msm_tool slug="csv-to-json"] follows that convention rather than splitting on every comma it sees, which is the difference between handling a quoted address correctly and having it fracture into extra columns the moment a comma appears inside it.
The delimiter is detected, not assumed
Comma, semicolon, tab and pipe are each tried against the first rows of the file, and whichever produces the most consistent column count across those rows is the one used for the whole conversion. That is what makes a semicolon-delimited European export load correctly without anyone having to say in advance which character the file actually uses.
Leading zeros are the classic casualty of type coercion
Values are coerced where they look like numbers or booleans, so a genuine number arrives as one instead of as text — useful almost everywhere except an identifier like a postcode that happens to start with a zero, which becomes a shorter number with the leading digit gone. Quoting that field in the source file, or turning coercion off entirely, is what keeps it as the text it actually is.
Duplicate column headers collapse into one key
An object cannot hold the same key twice, so two source columns sharing a header name end up as a single key in the output, with one value overwriting the other. Renaming the columns in the source before converting is the only fix, since nothing in the conversion itself can recover data that collided on the way in.
An unclosed quote swallows everything after it
A quote mark opened but never closed does not fail quietly — without the fix, everything from that point to the end of the file would be read as a single enormous value with no obvious cause. The parser reports the unclosed quote directly instead, which is considerably faster to act on than reverse-engineering one huge field back to the row where it went wrong.
CSV carries no encoding of its own
Nothing in the format states what character encoding a file was saved in, so a file written as Latin-1 and read as UTF-8 produces mangled accented characters with no signal anywhere in the file explaining why. That mismatch has to be fixed at the point the file is exported, since there is nothing in the CSV itself for a converter to detect and correct.