fork download
  1. import json
  2. s='"PN_#":9999,"Item":"Pear, Large","Vendor":["Farm"],"Class":["Food","Fruit"],"Sales Group":"59","Vendor ID (from Vendor)":[78]'
  3. js = json.loads(f'{{{s}}}')
  4. for key in js:
  5. if isinstance(js[key], list): # is it a list?
  6. if all(isinstance(x, str) for x in js[key]): # is it a list of strings?
  7. js[key] = ",".join(js[key])
  8. else:
  9. js[key] = ",".join(map(str, js[key]))
  10. print(js)
Success #stdin #stdout 0.03s 9756KB
stdin
Standard input is empty
stdout
{'PN_#': 9999, 'Item': 'Pear, Large', 'Vendor': 'Farm', 'Class': 'Food,Fruit', 'Sales Group': '59', 'Vendor ID (from Vendor)': '78'}