JSON requires all keys to be specified, so this is:
"{empty: false, ip: true}"
is not valid JSON. You need to pre-process it in order to be able to parse this JSON.
function preprocessJSON(str) { return str.replace(/("(\\.|[^"])*"|'(\\.|[^'])*')|(\w+)\s*:/g, function(all, string, strDouble, strSingle, jsonLabel) { if (jsonLabel) { return '"' + jsonLabel + '": '; } return all; }); }
(Try JSFiddle) It uses a simple regular expression to replace a word followed by a colon, with that word quoted inside double quotes. A regular expression will not indicate a label inside other lines.
Then you can calmly
data = JSON.parse(preprocessJSON(json));
source share