maartenmachiels maartenmachiels - 2 years ago 158
Javascript Question

jQuery: Convert string with comma separated values to specific JSON format

I've been losing hours over something that might be trivial:

I've got a list of comma-separated e-mail addresses that I want to convert to a specific JSON format, for use with the Mandrill API (

My string:

var to = ',,';

What (I think) it needs to be:

{"email": ""},
{"email": ""},
{"email": ""}

I've got a JSFiddle in which I almost have it I think:

I've been looking into several jQuery plugins, amongst which:
But I keep getting syntax errors.

Another post on SO suggested doing it by hand: JavaScript associative array to JSON

This might be a trivial question, but the Codecadamy documentation of the Mandrill API has been down for some time and there are no decent examples available.

Answer Source
var json = [];
var to = ',,';
var toSplit = to.split(",");
for (var i = 0; i < toSplit.length; i++) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download