# String Array from Exec Node to JSON Object

**URL:** <https://discourse.nodered.org/t/string-array-from-exec-node-to-json-object/91127>\
**Category:** General\
**Created:** [19 September 2024 20:44 UTC](https://discourse.nodered.org/t/string-array-from-exec-node-to-json-object/91127 "2024-09-19T20:44:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iotemylabs](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotemylabs/32/94700_2.png) [@iotemylabs](https://discourse.nodered.org/u/iotemylabs)\
**Post date:** [19 September 2024 20:44 UTC](https://discourse.nodered.org/t/string-array-from-exec-node-to-json-object/91127/1 "2024-09-19T20:44:29Z")

</div>

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:

```auto
"[↵ {↵ 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!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [19 September 2024 22:39 UTC](https://discourse.nodered.org/t/string-array-from-exec-node-to-json-object/91127/2 "2024-09-19T22:39:33Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [19 September 2024 22:45 UTC](https://discourse.nodered.org/t/string-array-from-exec-node-to-json-object/91127/3 "2024-09-19T22:45:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iotemylabs](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotemylabs/32/94700_2.png) [@iotemylabs](https://discourse.nodered.org/u/iotemylabs)\
**Post date:** [19 September 2024 23:41 UTC](https://discourse.nodered.org/t/string-array-from-exec-node-to-json-object/91127/4 "2024-09-19T23:41:12Z")

</div>

This is the output I get from using the Exec node for the [Hoarder CLI](https://docs.hoarder.app/command-line/) NPM Package

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [20 September 2024 05:45 UTC](https://discourse.nodered.org/t/string-array-from-exec-node-to-json-object/91127/5 "2024-09-20T05:45:57Z")

</div>

Looking at the github repo, they added [json output to the CLI interface](https://github.com/hoarder-app/hoarder/pull/181) not too long ago, perhaps updating the software may make it easier ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 December 2024 05:46 UTC](https://discourse.nodered.org/t/string-array-from-exec-node-to-json-object/91127/6 "2024-12-19T05:46:57Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
