Created
January 19, 2016 05:52
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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