Skip to content

Instantly share code, notes, and snippets.

@mauriciomassaia
Created January 19, 2016 05:52
Show Gist options
  • Save mauriciomassaia/3cb17d27430a38387760 to your computer and use it in GitHub Desktop.
Save mauriciomassaia/3cb17d27430a38387760 to your computer and use it in GitHub Desktop.
Replace single quotes with double quotes and add double quotes to a property
function addQuotes(match) {
return '"' + match.substr(0, match.length-1) + '":';
}
var t = "{tags:['000000000000000000000004', '000000000000000000000003', '300833B2DDD9014000000024', '300833B2DDD9014000000045', '300833B2DDD9014000000021', '000000000000000000000005', '000000000000000000000001', '300833B2DDD9014000000022', '000000000000000000000002']}";
var k = t.replace(/\'/g, '"');
k.replace(/[a-z]*\:/g, addQuotes);
/*
output:
{"tags":["000000000000000000000004", "000000000000000000000003", "300833B2DDD9014000000024", "300833B2DDD9014000000045", "300833B2DDD9014000000021", "000000000000000000000005", "000000000000000000000001", "300833B2DDD9014000000022", "000000000000000000000002"]}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment