Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSV to JSON cleanup example

A small Python command that turns a customer CSV into JSON while preserving identifiers and cleaning selected fields. It uses only the Python standard library.

The three sample records are fictional. This is a demonstration, not a client delivery. Development and review were AI-assisted.

Run

python3 convert.py sample-input.csv result.json
python3 test_convert.py

The included sample-output.json shows the expected result. Use a new output path when running the example; existing files are never replaced.

Behavior

Input must be UTF-8, with an optional BOM, and these exact columns:

customer_id,full_name,city
00017,"  Avery, Jo  ","  Montréal  "
00018,  Sam Patel ,  Austin
00019,Lina Chen,Boston

The command preserves customer_id as text, trims surrounding spaces from names and cities, and retains row order. Quoted commas, quoted newlines and Unicode text are supported. Malformed CSV, incorrect headers, invalid UTF-8 and wrong field counts are rejected before output creation.

Limits: 20,000 data rows and 10 MiB per input file. Header-only input produces an empty array. The input file is never modified, and output creation is exclusive. Errors return a nonzero status and a short message.

This example implements the schema above. Other file structures and transformation rules require changes to the script.

Verification

The checked version passed 13 tests on Ubuntu, plus a 20,000-row CRLF check and a comparison of newly generated output with the saved example. VERIFICATION.json records the run and file hashes. The tests exercise the actual command through subprocesses.

Custom work

Sovnode AI offers a custom CSV or JSON scripting package on Upwork. The package includes a script for an agreed schema, output format and transformation rules, with source, checks and run instructions. Please use fictional or redacted samples when discussing a project.

About

A tested Python CSV-to-JSON example with fictional records, preserved identifiers, clear validation and reusable source.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages