runtime
193 / 500
question 193 CSV JSON & JSONL · easy

Turn the product CSV into a JSON feed

A partner's website reads products as JSON, with real numbers and null for missing values, not CSV text. Convert the catalogue export.

Functionproducts_to_json(src, dest)
srcCSV with columns product_id,sku,name,category,list_price,discontinued_on; empty values are possible
Writesdest: a JSON array with one object per product, in file order: {"sku": …, "name": …, "price": …, "discontinued": …}
Valuesprice is a number (float), or null when list_price is empty; discontinued is the date text, or null when empty
Returnsthe number of products written
Examples
callproducts_to_json('products.csv', '_p0.json')returns8

Loading your progress…

Turn the product CSV into a JSON feed — Python practice · Runtime