Given a variable containing data that looks like an "array" with JSON Objects inside (even though it is not actually formatted as an array, starting and ending with curly braces):
{"x1","x2"},{"y1","y2"},{"z1","z2"}
How can I transform this so that the initial and final { curly braces } are replaced with square brackets [ ]? JavaScript does not recognize this format as an array, resulting in an error. Utilizing JSON.stringify or JSON.parse also proves ineffective since the structure is not genuine JSON/Array. Only when it is enclosed in [ square brackets ] will it be perceived as an array with JSON objects within:
[{"x1","x2"},{"y1","y2"},{"z1","z2"}]
I considered converting it into a string initially, and then substituting the first and last characters with [ and ] correspondingly. However, attempting String(value) on the original "array" results in errors, being interpreted as JSON leading to unexpected tokens if initialized.