I am parsing a file in order to make some documentation.
The string I am being returned is:
"([ {
href: "sass.html",
text: "Sass"
}, {
href: "components.html",
text: "Components"
}, {
href: "javascript.html",
text: "Javascript"
} ])
"
I would like to prettify this so I can output it into a pre tag. So the ideal output would be something like this:
"(
[
{
href: "sass.html",
text: "Sass"
},
{
href: "components.html",
text: "Components"
},
{
href: "javascript.html",
text: "Javascript"
}
]
)"
I am currently thinking I could remove all spacing in the string via:
string.replace(/\s/g,'')
Then do a bunch of splits to break each line apart and add spacing for indentation and rejoin it but this feels messy to me. Is there a better way I could so this?
Any advice is of course greatly appreciated.
This is different from: How can I beautify JSON programmatically? because i am dealing with a string on non-valid JSON.