javascript - convert invalid JSON string to JSON -


i have invalid json string following,

"{one: 'one', two: 'two'}" 

i tried use json.parse convert object. however, not valid json string. there functions can convert invalid format valid json string or directly convert object?

if example syntax same real json, jsonlint says need double quote name , value.

in case only, use these replace calls:

var jsontemp = yourjson.replace((/([\w]+)(:)/g), "\"$1\"$2"); var correctjson = jsontemp.replace((/'/g), "\""); //yourjson = "{one: 'one', two: 'two'}" //jsontemp = "{"one": 'one', "two": 'two'}" //correctjson = "{"one": "one", "two": "two"}" 

however should try work valid json in first place.


Comments

Popular posts from this blog

bash - How do you programmatically add a bats test? -

Unable to open serial port using Putty to bluetooth device on windows 7 64 bit -

java - Getting exception in JDBC thin driver -