Which would be best way to do these things?
Note: My array contains complex values means comma separated or object values in side string array & Arrays string quoted in double quotes and elements are in single quotes.
EX. str = "['sam', 'admin', '1062', 'Sam', 'True', '$$global_permissions#1062:manage_replenishment,purchase_order,reprint_invoice#1008', 'sameer@opnce.com', '9920580', 'en', '358', '{\"Sales-tax-details\":\"brand,category,supplierNo\",\"invoice-logs\":\"invoiceNo,eventDateTime,event\"}']"
Here i played with JSON.parse,
JSON.parse(str);
Uncaught SyntaxError: Unexpected token ' // this error i got on console
Then i tried,
JSON.parse(str.replace(/'/g, '"'))
Uncaught SyntaxError: Unexpected token S // this error i got on console
One more thing i wanted to explore here as,
if str contains following elements,
str = "['sam', 'admin', '1062', 'Sam', 'True', '$$global_permissions#1062:manage_replenishment,purchase_order,reprint_invoice#1008', 'sameer@opnce.com', '9920580', 'en', '358', '{}']"
for this str i tried,
JSON.parse(str.replace(/'/g, '"'))
Its working fine here,
Regards.
Perhaps,
EDIT: For the EX.
strfrom the question, the following should work: