0

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 "

Andy
  • 53,323
  • 11
  • 64
  • 89
Szymi
  • 1

1 Answers1

-3

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)
Spectric
  • 27,594
  • 6
  • 14
  • 39