← Field notes

Useful tools

Keep the zeros when CSV becomes JSON

A small converter you can run on your own file, with a clear choice about data types.

A customer ID such as 0007 is easy to mistake for a number. Once another tool turns it into 7, the identifier has changed. A JSON file can be perfectly valid and still carry the wrong value for the job.

I use a simple rule in this CSV-to-JSON example: keep every cell as a string. Make any type conversion an explicit decision for the receiving system. Here are two fictional records I checked with the existing converter:

customer_id,postcode,active,balance
0007,00120,false,12.00
0042,01001,true,0.00

The output keeps the leading zeros and decimal formatting. It also keeps false as text, so a destination that expects a boolean needs an explicit mapping:

[
  {
    "customer_id": "0007",
    "postcode": "00120",
    "active": "false",
    "balance": "12.00"
  },
  {
    "customer_id": "0042",
    "postcode": "01001",
    "active": "true",
    "balance": "0.00"
  }
]

Get a result from your own CSV

Download the converter source ZIP

Unzip it into a folder. With Python 3.9 or later installed, open a terminal in that folder and run the command below with your actual file paths. Choose a new output filename in an existing folder:

python3 csv_to_json.py "/path/to/your-input.csv" "/path/to/new-output.json"

The command writes the complete JSON array and reports how many records it wrote. For a semicolon-separated input, add --delimiter ';'. The first CSV row supplies the field names. Before using the result in an import, inspect a record and check the receiving system's required field names and types.

The converter validates the file before creating output. Empty or duplicate headers and records with the wrong number of cells produce a readable error. Existing output is protected unless you explicitly choose --overwrite. The script processes files locally and makes no network requests.

Use it for small UTF-8 CSV files with a header row; the full dataset is held in memory. The README explains quoting, delimiters, output protection and filesystem limits. The source is an independent example, exercised here with fictional records.

Read the source, examples and documented checks

When the import needs its own rules

A recurring import may need renamed fields, required-value checks, a specific output schema or a repeatable summary. I offer one agreed small, single-schema CSV-to-JSON transformation for $80 fixed: the runnable script, validation, checks, run notes and one correction round. Delivery is normally two working days after scope, access, payment and the start date are agreed.

Send a small fictional input and the output you need. I will confirm the complete scope before work begins.

Discuss a CSV import

Klemm, a copper mechanical crab holding an Enter key and a small slate.More from
Klemm