I have a folder of about a million JSON files and I wrote this to convert them quickly to CSV, but the formatting is not correct for the software I'm feeding them into.
Here's the code I'm using:
Do[(Export["CSV_OUT_" <> FileBaseName@jsonlist[[i]] <> ".csv",
Import[jsonlist[[i]]]]),{i, 1, Length[jsonlist]}];
The result looks like this: """from"" -> {""address_city"" -> ""MORGANVILLE"", ""address_country"" -> ""UNITED STATES"", ""address_line1"" -> ""123 TEST ST"", ""address_line2"" -> ""STE 1"", ""address_state"" -> ""NJ"", ""address_zip"" -> ""07751"", ""company"" -> """", ""name"" -> ""ELENA CROSS""}" """id"" -> ""sfm_c4kjaugl7u8psvqfatp0""" """imb_code"" -> ""897714123456789""" """mail_date"" -> """"" """mail_type"" -> ""usps_first_class""" etc.
The correct results would look like this in CSV format: from address_city,address_country,address_line1,address_line2,address_state,address_zip,company,name,id,imb_code,mail_date,mail_type,object,press_proof,size,target_delivery_date,,to address_city,address_country,address_line1,address_line2,address_state,address_zip,company,name MORGANVILLE,UNITED STATES,123 TEST ST,STE 1,NJ,7751,,ELENA CROSS,sfm_c4kjaugl7u8psvqfatp0,897714123456789,,usps_first_class,
Here are the contents of the JSON file:
{"from":{"address_city":"MORGANVILLE","address_country":"UNITED STATES","address_line1":"123 TEST ST","address_line2":"STE 1","address_state":"NJ","address_zip":"07751","company":null,"name":"ELENA CROSS"},"id":"sfm_c4kjaugl7u8psvqfatp0","imb_code":"897714123456789","mail_date":null,"mail_type":"usps_first_class","object":"self_mailer","press_proof":"https://lob-assets.com/sid-self_mailers/sfm_c4kjaugl7u8psvqfatp0.pdf?version=v1&expires=1635274618&signature=GHUTiyDy11kHT8VMN5UqwDfGuZmamn3W80c5LAd7Le5Hebwne5q-N7zwtmwD0sOfxeekezdSefZLnscBwiajCw","size":"6x18_bifold","target_delivery_date":null,"to":{"address_city":"MORGANVILLE","address_country":"UNITED STATES","address_line1":"123 TEST ST","address_line2":"STE 1","address_state":"NJ","address_zip":"07751","company":null,"name":"ELENA CROSS"}}
How can I export correctly formatted CSV files like the one above quickly?