Using split to get usable data from google bard response

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 ? :face_with_diagonal_mouth:

[{"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.

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 :vulcan_salute:

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 :vulcan_salute:

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

[{"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 :upside_down_face:

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.

[{"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":[]}]

yep its perfect for my use case
still amazed how you people use jsonata
:vulcan_salute: :upside_down_face:

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

[{"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":[]}]

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

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

like this without success
i

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

1 Like

this works graet

edited (that two regex works flawlessly)

and about confusion I just use ReplaceAll

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

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