Created
March 29, 2023 18:59
-
-
Save chrisfsmith/eb0c37266ffa27cb2f7f4956d729c033 to your computer and use it in GitHub Desktop.
Boop script to remove leading/trailing quotes, unescapes, and json formats your text
This file contains 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
/** | |
{ | |
"api":1, | |
"name":"Swarm", | |
"description":"Removes leading/trailing quotes, unescapes, and json formats your text", | |
"author":"Chris", | |
"icon":"broom", | |
"tags":"remove,slashes,escape,json,prettify,clean,indent" | |
} | |
**/ | |
function main(input) { | |
input.text = (input.text + '') | |
.replace(/^"(.*)$/, '$1') | |
.replace(/^(.*)"$/, '$1') | |
.replace(/\\(.?)/g, function (s, n1) { | |
switch (n1) { | |
case '\\': | |
return '\\' | |
case '0': | |
return '\u0000' | |
case '': | |
return '' | |
default: | |
return n1 | |
} | |
}); | |
try { | |
input.text = JSON.stringify(JSON.parse(input.text), null, 2); | |
} catch (error) { | |
input.postError("Invalid JSON") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment