I’m trying to stringify a multidimensional array with some string and the outerHTML of an anchor tag. For some unknown (to me) reason, it adds a double to the outerHTML text resulting in invalid JSON.
JavaScript
x
4
1
const a = document.getElementByTagName('a')[0].outerHTML;
2
const array = [["a", a],["b", a],["c", a]];
3
const json = JSON.stringify(array);
4
The result is:
JavaScript
1
4
1
'[["a","<a href=\"https://www.google.com/\" target=\"_blank\" rel=\"noopener noreferrer\">Link</a>"],
2
["b","<a href=\"https://www.google.com/\" target=\"_blank\" rel=\"noopener noreferrer\">Link</a>"],
3
["c","<a href=\"https://www.google.com/\" target=\"_blank\" rel=\"noopener noreferrer\">Link</a>"]]'
4
Advertisement
Answer
you need to console.log
it
from experience, I can tell that you just copied this string from your dev console, after letting it debug-print the contents of that JSON Serialization.