String to array - json.parse

More related to javascript, but am not able to find a working example (that works in NR).

I extract text from a website, the text is a string, but contains an (multidimensional) array.

Function used to extract the text:

const regex = /\[(.*?).*\]/gm;
let m;

m = regex.exec(msg.payload)
return {payload:m[0]}



a string.

Now I thought to use JSON.parse(m[0]) to parse it as an array, but it doesn't like it:

"SyntaxError: Unexpected token , in JSON at position 525"

What am I missing ?

Can you paste the full string output from debug node into a code section between backticks so we can see what might be happening?

(Your screen shot is cut off and not useful for someone who might try to recreate, copy/paste fix this for you)

Yeah it is a very long output, so I didn't bother.

But your comment triggered me to check the actual array (duh should have started there), ie. is it an array: and it wasn't, it was missing additional [ ... ] I was mislead by the initial [[, working now, thanks!

1 Like

Glad I could help :laughing:

And looking my regex, I strip the [ ] off, I should have known :weary: