Hey how can I convert json string into a list ?
[[1, 'group1', '#5bc6e1'], [2, 'group2', '#8ec936']]
I tried to use .split but it splited it wrong
I JSON.parse dont work because it has '
and not "
Hey how can I convert json string into a list ?
[[1, 'group1', '#5bc6e1'], [2, 'group2', '#8ec936']]
I tried to use .split but it splited it wrong
I JSON.parse dont work because it has '
and not "
You can replace all single quotes with double quotes (with String.replaceAll
), then parse with JSON.parse
:
const str = "[[1, 'group1', '#5bc6e1'], [2, 'group2', '#8ec936']]";
const result = JSON.parse(str.replaceAll("'", '"'));
console.log(result)