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.
Function
products_to_json(src, dest)srcCSV with columns
product_id,sku,name,category,list_price,discontinued_on; empty values are possibleWrites
dest: a JSON array with one object per product, in file order: {"sku": …, "name": …, "price": …, "discontinued": …}Values
price is a number (float), or null when list_price is empty; discontinued is the date text, or null when emptyReturnsthe number of products written
Examples
callproducts_to_json('products.csv', '_p0.json')returns8