Created
August 28, 2019 10:51
-
-
Save GenesisCoast/0e2c7f8670409323c926e67f8e7ef5d4 to your computer and use it in GitHub Desktop.
Converts a ServiceNow glide record into a JSON string.
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 stringifyGr(record) { | |
var result = ["{"]; | |
var multiline = false; | |
for (var key in record) { | |
if(record.hasOwnProperty(key)) { | |
var value = record[key].toString(); | |
switch (typeof value) { | |
case "undefined": | |
case "function": | |
case "unknown": | |
break; | |
default: | |
if (multiline) { | |
result.push(','); | |
} | |
result.push( | |
JSON.stringify(key), | |
':', | |
value === null ? "null" : JSON.stringify(value) | |
); | |
multiline = true; | |
break; | |
} | |
} | |
} | |
result.push("}"); | |
return result.join(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment