# Using split to get usable data from google bard response

**URL:** <https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826>\
**Category:** General\
**Created:** [14 July 2023 18:26 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826 "2023-07-14T18:26:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)\
**Post date:** [14 July 2023 18:26 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/1 "2023-07-14T18:26:20Z")

</div>

I have a flow that use my browser cookies to make a request on google bard.  
I'm getting the data and I guess it's some how an incomplete json ? 🫤

```auto
[{"id":"4d80142b28554cfd","type":"split","z":"edf575ef.a74f58","name":"","splt":"\\\",[\\\"","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":490,"y":1220,"wires":[["6152be3de9e0d3dd"]]},{"id":"d3681eb1df2afbd1","type":"inject","z":"edf575ef.a74f58","name":"incoming data","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":")]}' 2787 [[\"wrb.fr\",null,\"[null,[\\\"c_6d7f62e9227e7e60\\\",\\\"r_6d7f62e9227e7499\\\"],[[\\\"what is node-red?\\\",1],[\\\"Why would I use Node-RED?\\\",4],[\\\"What is the use of Node-RED in IoT?\\\",4]],null,[[\\\"rc_6d7f62e9227e73b6\\\",[\\\"Node-RED is a flow-based development tool for visual programming. It allows you to wire together hardware devices, APIs, and online services in new and interesting ways. Node-RED is built on Node.js, a popular JavaScript runtime environment.\\\\n\\\\nHere are some of the benefits of using Node-RED:\\\\n\\\\n* **Ease of use:** Node-RED is a very easy-to-use tool, even for those with no prior programming experience. The visual editor makes it easy to create flows, and the wide range of pre-built nodes makes it possible to do a lot without writing any code.\\\\n* **Flexibility:** Node-RED is a very flexible tool. You can use it to create a wide variety of applications, from simple data logging to complex IoT systems.\\\\n* **Community:** Node-RED has a large and active community of ...","payloadType":"str","x":270,"y":1220,"wires":[["4d80142b28554cfd"]]},{"id":"6152be3de9e0d3dd","type":"debug","z":"edf575ef.a74f58","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":1220,"wires":[]}]

```

this portion (in red square) of data is enough for me.

 ![df](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/caa23b83ca5ef642a329404cd8c8f8dbcdac7415.jpeg)

My question is how to get the data I want without using 2 split nodes end to end?  
Is there any way to dismiss first message?(tried trigger node and delay node without success) to get what I want (always second message)

or am I getting the data incomplete?  
I feel like I'm missing/not understanding something common.  
thank you for your help 🖖

---

<div class="post-metadata">

**Author:** ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)\
**Post date:** [14 July 2023 19:14 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/2 "2023-07-14T19:14:58Z")

</div>

Updating my own post now I know that dbug node putting ... to simplify things  
I'm getting full data I see it when I use a text node on dashboard.

so my question is now hot to split that text and get more readable text 🖖

---

<div class="post-metadata">

**Author:** ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)\
**Post date:** [14 July 2023 19:53 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/3 "2023-07-14T19:53:24Z")

</div>

updating again  
now I'm sure I'm getting full data and the data I need always between ` \",[\"` this and `\"],[]`  
just tried to get it with two split nodes without success

```auto
[{"id":"51b04d4263aac52a","type":"split","z":"9caef6f240cf8f85","name":"","splt":"\\\"],[]","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":270,"y":600,"wires":[[]]},{"id":"8f048d33673be900","type":"split","z":"9caef6f240cf8f85","name":"","splt":"\\\",[\\\"","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":130,"y":600,"wires":[["51b04d4263aac52a"]]}]

```

maybe I can use some regex or native java hocuspocus to get the string I want 🙃

---

<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:** [14 July 2023 20:24 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/4 "2023-07-14T20:24:47Z")

</div>

Where is this data coming from? Is there other parts of this data?  
If there is more you maybe able to rejoin it and parse the correctly formed json.

Alternatively This example may help.

```auto
[{"id":"d3681eb1df2afbd1","type":"inject","z":"b9860b4b9de8c8da","name":"incoming data","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":")]}' 2787 [[\"wrb.fr\",null,\"[null,[\\\"c_6d7f62e9227e7e60\\\",\\\"r_6d7f62e9227e7499\\\"],[[\\\"what is node-red?\\\",1],[\\\"Why would I use Node-RED?\\\",4],[\\\"What is the use of Node-RED in IoT?\\\",4]],null,[[\\\"rc_6d7f62e9227e73b6\\\",[\\\"Node-RED is a flow-based development tool for visual programming. It allows you to wire together hardware devices, APIs, and online services in new and interesting ways. Node-RED is built on Node.js, a popular JavaScript runtime environment.\\\\n\\\\nHere are some of the benefits of using Node-RED:\\\\n\\\\n* **Ease of use:** Node-RED is a very easy-to-use tool, even for those with no prior programming experience. The visual editor makes it easy to create flows, and the wide range of pre-built nodes makes it possible to do a lot without writing any code.\\\\n* **Flexibility:** Node-RED is a very flexible tool. You can use it to create a wide variety of applications, from simple data logging to complex IoT systems.\\\\n* **Community:** Node-RED has a large and active community of \\\"],[]","payloadType":"str","x":150,"y":3400,"wires":[["b01af630132bb83f"]]},{"id":"b01af630132bb83f","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$substringBefore( $substringAfter( $$.payload, '\\\\\",[\\\\\"'), '\\\\\"],[]')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":3400,"wires":[["6152be3de9e0d3dd"]]},{"id":"6152be3de9e0d3dd","type":"debug","z":"b9860b4b9de8c8da","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":3400,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)\
**Post date:** [14 July 2023 20:39 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/5 "2023-07-14T20:39:35Z")

</div>

yep its perfect for my use case  
still amazed how you people use jsonata  
🖖 🙃

---

<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:** [14 July 2023 21:39 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/6 "2023-07-14T21:39:25Z")

</div>

Just for info.  
Here is the lowcode way using split and switch nodes.

```auto
[{"id":"d3681eb1df2afbd1","type":"inject","z":"b9860b4b9de8c8da","name":"incoming data","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":")]}' 2787 [[\"wrb.fr\",null,\"[null,[\\\"c_6d7f62e9227e7e60\\\",\\\"r_6d7f62e9227e7499\\\"],[[\\\"what is node-red?\\\",1],[\\\"Why would I use Node-RED?\\\",4],[\\\"What is the use of Node-RED in IoT?\\\",4]],null,[[\\\"rc_6d7f62e9227e73b6\\\",[\\\"Node-RED is a flow-based development tool for visual programming. It allows you to wire together hardware devices, APIs, and online services in new and interesting ways. Node-RED is built on Node.js, a popular JavaScript runtime environment.\\\\n\\\\nHere are some of the benefits of using Node-RED:\\\\n\\\\n* **Ease of use:** Node-RED is a very easy-to-use tool, even for those with no prior programming experience. The visual editor makes it easy to create flows, and the wide range of pre-built nodes makes it possible to do a lot without writing any code.\\\\n* **Flexibility:** Node-RED is a very flexible tool. You can use it to create a wide variety of applications, from simple data logging to complex IoT systems.\\\\n* **Community:** Node-RED has a large and active community of \\\"],[]","payloadType":"str","x":150,"y":3400,"wires":[["8f048d33673be900"]]},{"id":"8f048d33673be900","type":"split","z":"b9860b4b9de8c8da","name":"","splt":"\\\",[\\\"","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":210,"y":3300,"wires":[["a313a653c33c8a8c"]]},{"id":"a313a653c33c8a8c","type":"switch","z":"b9860b4b9de8c8da","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":3300,"wires":[["51b04d4263aac52a"]]},{"id":"51b04d4263aac52a","type":"split","z":"b9860b4b9de8c8da","name":"","splt":"\\\"],[]","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":490,"y":3300,"wires":[["1f501b08f7bf3d1d"]]},{"id":"1f501b08f7bf3d1d","type":"switch","z":"b9860b4b9de8c8da","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":3300,"wires":[["6152be3de9e0d3dd"]]},{"id":"6152be3de9e0d3dd","type":"debug","z":"b9860b4b9de8c8da","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":3400,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)\
**Post date:** [14 July 2023 21:50 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/7 "2023-07-14T21:50:48Z")

</div>

wow this way more understandable than jasonata for me 🖖  
thank you so much this works flawlessly.  
now I'm trying to split the string

```auto
var text = msg.payload;
msg.result = text.replace(/\\n\\n/g, "\n");
return msg;

```

like this without success  
i

---

<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:** [14 July 2023 22:20 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/8 "2023-07-14T22:20:37Z")

</div>

Slight confused look, are you spliting or replacing?

` \` is a special char, in the regex you need to escape it as well if you want to seach for just `\` so the regex would be `/\\\\n\\\\n/g`.  
or to replace any number of occurrences `/(\\\\n)+/g`  
[edit] fixed typo in regex

---

<div class="post-metadata">

**Author:** ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)\
**Post date:** [14 July 2023 22:29 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/9 "2023-07-14T22:29:50Z")

</div>

this works graet

> [@E1cid](#):
>
> /\\n\\n/g

edited (that two regex works flawlessly)

---

<div class="post-metadata">

**Author:** ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)\
**Post date:** [14 July 2023 22:34 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/10 "2023-07-14T22:34:35Z")

</div>

and about confusion I just use ReplaceAll

---

<div class="post-metadata">

**Author:** ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)\
**Post date:** [16 July 2023 16:15 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/11 "2023-07-16T16:15:33Z")

</div>

thank you for your help now I have a perfect bard ai implemented just with native nodes. 🖖

---

<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:** [30 July 2023 16:16 UTC](https://discourse.nodered.org/t/using-split-to-get-usable-data-from-google-bard-response/79826/12 "2023-07-30T16:16:32Z")

</div>

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