'How to remove strings from a json file

enter image description here

I am trying to convert it into a json file but the thing is that the single quotations marks are in between the two brackets instead of being outside them so I cannot use JSON.parse() to convert it to a json so I don't know how to get rid of those single quotations at the start and end of the data.



Solution 1:[1]

You can use regex to chop off the brackets:

    const reg = [/\[\'/, /\']+$/];
    const string = "['YOUR JSON']";
    const str = string.replace(reg[0], "");
    const newStr = str.replace(reg[1], "");
    console.log(newStr);

I hope that will solve your problem

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mark Zveni