String Array from Exec Node to JSON Object

Hi!

I have been racking my brain for hours trying to get a JSON output.

After calling a CLI command using the Exec node, I get this string array:

"[↵ {↵ id: 'djtxrc3qclpy62pvpleh33vs',↵ createdAt: 2024-09-19T19:51:33.000Z,↵ title: null,↵ archived: false,↵ favourited: false,↵ taggingStatus: 'success',↵ note: null,↵ tags: [ 'youtube', 'Streaming Services', 'TV Shows' ],↵ content: {↵ type: 'link',↵ url: 'https://youtu.be/l4FgyRVik1Q?si=Cz05aPLTY3Znj1ZL',↵ title: 'video title',↵ description: 'videodescrip',↵ imageUrl: 'https://i.ytimg.com/vi/maxresdefault.jpg',↵ imageAssetId: 'd8737905-f785-4308-bf61-01bfa4568930',↵ screenshotAssetId: '73185ac1-1c86-4800-a9c3-3b8e3688caea',↵ favicon: 'https://www.youtube.com/s/desktop/img/favicon_144x144.png',↵ htmlContent: '<div id="r... <CROPPED>',↵ crawledAt: 2024-09-19T19:52:08.000Z↵ }↵ }↵]↵"

I am trying to:

  • Turn this String Array into a JSON Array
  • Grab the first entry in that array and output it into a JSON Object
  • Extract the 'id' and 'url' fields and output them in its own JSON

I am struggling to properly get this into a JSON Array, any ideas?

TIA!

There is a strange non printable char in there, the timestamp have no quotes and the property names have no quotes.
So you can spend time creating regex to replace all non quote strings and property names with double quotes, and replace the non printable char with an empty string. the parse the corrected JSON. or add quotes to the time stamp and replace non printable chars, then use the evil eval function.
Be sure there is no hidden executable code hidden in the return cli message, as eval will run any valid Javascript.
e.g

msg.payload = eval(msg.payload.replace(/↵/g,"").replace(/(?<=At: )([^\s,]*)/g, "'$1'"))
return msg;

Is this on Windows or Linux?

What is the CLI command? It may be easier to tweek it to produce a cleaner output than to reformat in Node-red

This is the output I get from using the Exec node for the Hoarder CLI NPM Package

Looking at the github repo, they added json output to the CLI interface not too long ago, perhaps updating the software may make it easier ?