{"ScriptPreparationCode":"var obj = {\r\n \u0022product\u0022: \u0022Live JSON generator\u0022,\r\n \u0022lock\u0022: \u0022test\u0022,\r\n \u0022version\u0022: 3.1,\r\n \u0022releaseDate\u0022: \u00222014-06-25T00:00:00.000Z\u0022,\r\n \u0022demo\u0022: true,\r\n \u0022person\u0022: {\r\n \u0022id\u0022: 12345,\r\n \u0022name\u0022: \u0022John Doe\u0022,\r\n \u0022phones\u0022: {\r\n \u0022home\u0022: \u0022800-123-4567\u0022,\r\n \u0022mobile\u0022: \u0022877-123-1234\u0022\r\n },\r\n \u0022email\u0022: [\r\n \u0022jd@example.com\u0022,\r\n \u0022jd@example.org\u0022\r\n ],\r\n \u0022dateOfBirth\u0022: \u00221980-01-02T00:00:00.000Z\u0022,\r\n \u0022registered\u0022: true,\r\n \u0022emergencyContacts\u0022: [\r\n {\r\n \u0022name\u0022: \u0022Jane Doe\u0022,\r\n \u0022phone\u0022: \u0022888-555-1212\u0022,\r\n \u0022relationship\u0022: \u0022spouse\u0022\r\n },\r\n {\r\n \u0022name\u0022: \u0022Justin Doe\u0022,\r\n \u0022phone\u0022: \u0022877-123-1212\u0022,\r\n \u0022relationship\u0022: \u0022parent\u0022\r\n }\r\n ]\r\n }\r\n}","TestCases":[{"Name":"cleanJson (old)","Code":"const cleanJson = (obj) =\u003E {\r\n // LOOP THROUGH ARRAYS\r\n let cleaned;\r\n if (obj instanceof Array) {\r\n cleaned = [];\r\n for (const elem of obj) {\r\n cleaned.push(cleanJson(elem));\r\n }\r\n return cleaned;\r\n\r\n // CLEAN AN OBJECT\r\n } else if (obj \u0026\u0026 typeof obj === \u0022object\u0022) {\r\n cleaned = {};\r\n for (const key of Object.keys(obj)) {\r\n // If key starts with \u0022$\u0022 it is a private variable\r\n // If the key starts with _ we are expecting it to be\r\n // _id, __v or __t, all of which we don\u0027t allow in the clean\r\n // JSON as it is not something we want affecting Mongo\r\n switch (key.charAt(0)) {\r\n case \u0022$\u0022:\r\n case \u0022_\u0022:\r\n continue;\r\n }\r\n\r\n // If the key is not one of those on our persistance\r\n // blacklist, we clean the sub-JSON\r\n cleaned[key] = cleanJson(obj[key]);\r\n }\r\n return cleaned;\r\n } else {\r\n return obj;\r\n }\r\n};\r\n\r\nlet newObj = cleanJson(obj);\r\ndelete newObj.lock;","IsDeferred":false},{"Name":"cleanJson (new, ignore lock)","Code":"const cleanJson = (obj) =\u003E {\r\n let out = obj;\r\n\r\n if (Array.isArray(obj)) {\r\n out = [];\r\n for (let index = 0; index \u003C obj.length; \u002B\u002Bindex) {\r\n const subArray = obj[index];\r\n out.push(Array.isArray(subArray) || typeof subArray === \u0022object\u0022 ? cleanJson(subArray) : subArray);\r\n }\r\n } else if (typeof obj === \u0022object\u0022) {\r\n out = {};\r\n for (const key in obj) {\r\n const subObject = obj[key];\r\n switch (key.charAt(0)) {\r\n case \u0022$\u0022:\r\n case \u0022_\u0022:\r\n continue;\r\n }\r\n if (key === \u0022lock\u0022) { continue; }\r\n out[key] = Array.isArray(subObject) || typeof subObject === \u0022object\u0022 ? cleanJson(subObject) : subObject;\r\n }\r\n }\r\n return out;\r\n};\r\n\r\ncleanJson(obj);","IsDeferred":false},{"Name":"cleanJson (new, delete lock)","Code":"const cleanJson = (obj) =\u003E {\r\n let out = obj;\r\n\r\n if (Array.isArray(obj)) {\r\n out = [];\r\n for (let index = 0; index \u003C obj.length; \u002B\u002Bindex) {\r\n const subArray = obj[index];\r\n out.push(Array.isArray(subArray) || typeof subArray === \u0022object\u0022 ? cleanJson(subArray) : subArray);\r\n }\r\n } else if (typeof obj === \u0022object\u0022) {\r\n out = {};\r\n for (const key in obj) {\r\n const subObject = obj[key];\r\n switch (key.charAt(0)) {\r\n case \u0022$\u0022:\r\n case \u0022_\u0022:\r\n continue;\r\n }\r\n out[key] = Array.isArray(subObject) || typeof subObject === \u0022object\u0022 ? cleanJson(subObject) : subObject;\r\n }\r\n }\r\n return out;\r\n};\r\n\r\nlet newObj = cleanJson(obj);\r\ndelete newObj.lock;","IsDeferred":false},{"Name":"cleanJson (new, mark lock)","Code":"const cleanJson = (obj) =\u003E {\r\n let out = obj;\r\n\r\n if (Array.isArray(obj)) {\r\n out = [];\r\n for (let index = 0; index \u003C obj.length; \u002B\u002Bindex) {\r\n const subArray = obj[index];\r\n out.push(Array.isArray(subArray) || typeof subArray === \u0022object\u0022 ? cleanJson(subArray) : subArray);\r\n }\r\n } else if (typeof obj === \u0022object\u0022) {\r\n out = {};\r\n for (const key in obj) {\r\n const subObject = obj[key];\r\n switch (key.charAt(0)) {\r\n case \u0022$\u0022:\r\n case \u0022_\u0022:\r\n continue;\r\n }\r\n out[key] = Array.isArray(subObject) || typeof subObject === \u0022object\u0022 ? cleanJson(subObject) : subObject;\r\n }\r\n }\r\n return out;\r\n};\r\n\r\nlet newObj = cleanJson(obj);\r\nnewObj.lock = undefined;","IsDeferred":false}]}