DATA REPRESENTATION CHECKS

Checking case and spaces in CSV property names

The CSV to JSON converter keeps header text as written. This guide shows how case and spaces produce separate property names and what to check before merging fields.

Exact text becomes the property name

With the header option on, the first record supplies the property names of every object. The converter copies that text into the names with no trimming and no change of case. A header written as Id and one written as id become two different properties. A name with a space in front keeps the space as part of the name. This is the safe, literal behavior, but it surprises people who expect a tool to normalize names the way a spreadsheet user would read them. What you type in the header row is exactly what appears in the JSON. A header such as Total Price keeps its internal space too, so the property is Total Price with a space, and code that expects total_price or TotalPrice will not find it. Every character between the commas counts, including characters that were added by a careless export.

Three names that look alike

The header id, ID, space then id, followed by the data row 1, 2, 3, yields one object with three properties. The name id holds 1, the name ID holds 2, and the name with the leading space holds 3. To a reader scanning the output they look like repeats of one field. To the program they are three different keys, and all three can be present in one object without conflict. The converter treats the case difference and the space as part of each name. A second pair makes the same point with letters: the header Name, name and the row 1, 2 gives an object with Name equal to 1 and name equal to 2. Both keys coexist, and a consumer that folds case would see two values for one field and has to decide which to keep.

Where leading and trailing spaces come from

Spaces in headers usually come from how the file was written. A line such as id, name, email with a space after each comma produces the names id, then a space and name, then a space and email. The first is clean and the rest carry a space. Hand-edited files, exports from reports and copied tables are common sources. The space is invisible when printed, which makes the result look correct until a lookup by the clean name returns nothing. Looking at the JSON output closely helps: a key whose opening quote is followed by a gap, as in a quote, space, name, quote, shows the problem, while a screen reader or a terminal that trims whitespace may hide it. Encoding the key with the ASCII converter and looking for a 32 at the start settles the question.

Case differences in practice

Different systems write the same field with different capitalization: id, Id, ID, userId, user_id. A file produced by one tool and consumed by another can carry the wrong case. In a case-sensitive language such as JavaScript, row.id and row.ID refer to different properties. Some databases and spreadsheets ignore case when matching columns, so a file may work in one place and fail in another. SQL identifiers are often case-insensitive unless quoted, while JSON keys are always case-sensitive, so a header that passes one test can fail the next. Seeing the exact names in the JSON output, without any silent folding, tells you what a case-sensitive consumer will actually receive.

Do not assume one check covers every collision

The converter rejects headers that repeat the same exact name, such as id and id in the same row, because the object could not hold two properties with one key. That guard is for exact duplicates only. It does not catch names that differ by case or by a space, as the example above shows. Do not assume a parser's exact-name uniqueness check prevents every downstream collision, because the guard only compares the strings as written. A later system may treat them as equal.

When another system normalizes names

If a downstream system trims spaces or ignores case, three distinct keys can collapse into one there, and one value will overwrite the others. In the example, id, ID and the spaced id would all become the same name, and only one of the three values would survive. Define that transformation on purpose and check its results separately. A short list of every header name after normalization, with a count of how many map to each, reveals the collisions before any data is merged. In a spreadsheet, a formula that trims and lowercases each header and then counts repeats does the same job. Any count above one marks a group of names that will collide, and the fix is to rename them at the source with a rule everyone on the project can read.

Cleaning headers deliberately

If you want clean names, apply the cleanup as a visible step before conversion: trim leading and trailing spaces, choose one case convention, and replace internal spaces with a fixed character. Then convert and compare the output against the expected set of names. Keeping the original file untouched and writing the cleaned version separately preserves a record of what the source contained, which helps when a question comes up later about why a column changed its name. A small mapping table from original header to cleaned header is worth keeping beside the data. It documents each change, lets you reverse the cleanup if a recipient needs the original labels, and gives reviewers one place to check that nothing was renamed by accident.

Quoted headers

Quotes around a header do not change the rule. A quoted name keeps the text inside the quotes exactly, including spaces, and the quotes themselves are not part of the name. So the header row with the names in quotes and a space inside the second name gives a property with that space. Quoting is useful when a name contains a comma, and it does not trim or fold anything. The same literal approach applies to the data fields, whose spaces are also kept as written.

What the check demonstrates

The example shows that the converter is literal, which is useful for debugging because the output reflects the file. It does not tell you which names are right for your schema, and it does not merge or rename columns. After converting, list the property names and compare them with the names your destination expects, character for character. A stray capital or a leading space found at this stage costs one edit, while the same problem found after merging records costs far more.

Reproduce the checks

Distinct exact header names

Open the Csv To Json Converter and enter:

CSV input
id,ID, id
1,2,3
First row contains headers
true

Expected output:

Rows

[
  {
    "id": "1",
    "ID": "2",
    " id": "3"
  }
]

Case and the leading space remain part of the names.

Exact duplicate rejected

Open the Csv To Json Converter and enter:

CSV input
id,id
1,2
First row contains headers
true

Expected rejection:

unique

An actual exact-name duplicate fails the header guard.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks