# Look in payload for a specific string of text

**URL:** <https://discourse.nodered.org/t/look-in-payload-for-a-specific-string-of-text/37864>\
**Category:** General\
**Created:** [22 December 2020 03:45 UTC](https://discourse.nodered.org/t/look-in-payload-for-a-specific-string-of-text/37864 "2020-12-22T03:45:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nappyjim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nappyjim/32/34077_2.png) [@nappyjim](https://discourse.nodered.org/u/nappyjim)\
**Post date:** [22 December 2020 03:45 UTC](https://discourse.nodered.org/t/look-in-payload-for-a-specific-string-of-text/37864/1 "2020-12-22T03:45:37Z")

</div>

I'm an idiot,figured it out.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/81bc271bec0f9fc280c2b9b10251727cbe599d2c.png)

Hi guys,

I'm a home assistant user, just beginning my journey with Node red. I know home assistant node red isnt quite the same, but I think my question is relevant for both.

Quite simply, in the pictured flow, what do I need to place in between the inject node and the "Turn on light" node that will ONLY turn on the light if the payload includes "caption" : "ok" ??

This is just a simple example of a more complex flow I am doing. Im just stuck on how to parse the payload to look for specific text.

(((If you care, I am using BeSpoken to send silent command to my amazon alexa. The payload is what it returns. It only returns a "caption: ok" if the command is successful. I want to use the existence/non existence of "caption:ok" to trigger a message being sent to my smartphone)))

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/46ea070ce3b98885a21fed769e5d9d24d67a2934.png)

```auto
[{"id":"9228fdb7.e0546","type":"inject","z":"46dac922.3363f8","name":"inject","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"\"{\"message\": \"Turn off office light\", \"card\": null, \"sessionTimeout\": 0, \"streamURL\": null, \"transcript\": \"okay\", \"transcriptAudioURL\": null, \"display\": null, \"caption\": \"ok\", \"debug\": {\"deviceInteractionDuration\": 3.116769552230835}\"","payloadType":"str","x":630,"y":80,"wires":[["f4a65240.b372c","8dab3c0.f0e33c8"]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 December 2020 06:09 UTC](https://discourse.nodered.org/t/look-in-payload-for-a-specific-string-of-text/37864/2 "2020-12-22T06:09:41Z")

</div>

Don't worry.

You aren't the only one to make mistakes. (Ask anyone here about me)

Good you sorted it out.

You may want to mark this as solved.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [22 December 2020 09:20 UTC](https://discourse.nodered.org/t/look-in-payload-for-a-specific-string-of-text/37864/3 "2020-12-22T09:20:48Z")

</div>

Hello,

Just for future reference the way you found will work fine but something you should know when you meet a string like this again is that this is a [string which contains a json](https://en.m.wikipedia.org/wiki/JSON).  
You can feed it through the json node from the palette and you will get an [actual javascript object](https://www.w3schools.com/js/js_objects.asp) in the `msg.payload` which would mean that you can work directly with it‘s properties in switch/change/function node with much more freedom than the string represents.  
For example you could than use:  
if `msg.payload.caption` == `ok` in a switch node as a rule instead of checking the whole string with contains.  
This is especially useful if you‘d want to work with other properties of an input message down the line.  
All that said your solution is a fine quick and dirty solution.

Johannes

---

<div class="post-metadata">

**Author:** ![nappyjim](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nappyjim/32/34077_2.png) [@nappyjim](https://discourse.nodered.org/u/nappyjim)\
**Post date:** [22 December 2020 14:22 UTC](https://discourse.nodered.org/t/look-in-payload-for-a-specific-string-of-text/37864/4 "2020-12-22T14:22:38Z")

</div>

@JGKK  
Thanks, that worked too. I may do that so that in future I can look back for on this flow as an example for futures flows. Thanks

---

<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:** [5 January 2021 14:22 UTC](https://discourse.nodered.org/t/look-in-payload-for-a-specific-string-of-text/37864/5 "2021-01-05T14:22:46Z")

</div>

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