Skip to content

Instantly share code, notes, and snippets.

@GenesisCoast
Created August 28, 2019 10:51
Show Gist options
  • Save GenesisCoast/0e2c7f8670409323c926e67f8e7ef5d4 to your computer and use it in GitHub Desktop.
Save GenesisCoast/0e2c7f8670409323c926e67f8e7ef5d4 to your computer and use it in GitHub Desktop.
Converts a ServiceNow glide record into a JSON string.
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