I have a string that I convert to an array:
var data = "[[1, 2, 3,], [3, 2, 1]]";
var array = JSON.parse(data.replace(/,\s*]/g, ']'));
I need to be able to handle floating points, i.e input of this form:
var data = "[[2.,23.,1.5904], [4.,23,1.6208]]";
Using the browser console, when I try to do:
var ar = JSON.parse(data.replace(/,\s*]/g, ']'));
I get this error:
SyntaxError: JSON.parse: unterminated fractional number at line 1 column 5 of the JSON data
I guess it has something to do with the regexp of the JSON.parse()
, but I am not strong in regexp yet, so I don't have a clue.
I have played around with this: https://regexone.com/ which actually helped understanding pretty much, but I'm still not able to fix my problem.
This question is kind of an extension to my previous question (which is solved):
Convert string of array, with array of array(s)
What I didn't think of at the time, was that I also need to be able to handle floating points