Replace single to double quotes and wrap string with double quotes


#1

How to replace single to double quotes and wrap strings with double quotes in JSON?

So that :

 { 
        'ns2:users': {
                '$':  { 
                   'xmlns:ns2': 'identity.rest.mgmt.acs.nm.apple.com' 
           },
         User: [{ 
                 description: [ 'Seb' ],
                 id: [ 'XXX' ],             
                 name: [ 'SEB88' ],
                 changePassword: [ 'false' ],
                 created: [ 'Aug 19 2015 16:28:28' ],

Becomes

{
	"ns2:users": {
		"$": {
		   "xmlns:ns2": "identity.rest.mgmt.acs.nm.apple.com"
		},
 	"User": [{
		 "description": ["Seb"],
		 "id": ["XXX"],
	         "name": ["SEB88"],
		 "changePassword": ["false"],
		 "created": ["Mar 20 2015 08:42:26"],

#2

You could try to use regular expressions. Which will be complicated due to the edge cases you have to consider (like, a user’s name being O'Malley)


#3

Hi rhywden

Thanks for the edge cases, didn’t think about these names.