Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  166] [ 1]  / answers: 1 / hits: 27920  / 11 Years ago, fri, august 30, 2013, 12:00:00

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 (https://mandrillapp.com/api/docs/messages.JSON.html)



My string:



var to = '[email protected],[email protected],[email protected]';


What (I think) it needs to be:



[
{email: [email protected]},
{email: [email protected]},
{email: [email protected]}
]


I've got a JSFiddle in which I almost have it I think:
http://jsfiddle.net/5j8Z7/1/



I've been looking into several jQuery plugins, amongst which: http://code.google.com/p/jquery-json
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.


More From » jquery

 Answers
2
var json = [];
var to = '[email protected],[email protected],[email protected]';
var toSplit = to.split(,);
for (var i = 0; i < toSplit.length; i++) {
json.push({email:toSplit[i]});
}

[#76000] Thursday, August 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyterryp

Total Points: 290
Total Questions: 92
Total Answers: 95

Location: Montenegro
Member since Sun, May 7, 2023
1 Year ago
;