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
  • 61,948
  • 13
  • 68
  • 95
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
  • 30,714
  • 6
  • 20
  • 43