# Search for JSON property -\> swtich if match/ not match

**URL:** <https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241>\
**Category:** General\
**Created:** [8 March 2021 07:02 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241 "2021-03-08T07:02:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eintracht00](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@Eintracht00](https://discourse.nodered.org/u/Eintracht00)\
**Post date:** [8 March 2021 07:02 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241/1 "2021-03-08T07:02:22Z")

</div>

Hey is there a way to search in a JSON data for a property for example key, if its there under the part msg.payload or like msg.payload.js than filter for this {the function for filter i got}, and if it is not there give an error phrase like undefined{this function i got too}, but i don't know how i can search for a JSON data property for the switch, i tried regex or contains, but not works..

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 March 2021 07:21 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241/2 "2021-03-08T07:21:54Z")

</div>

Please read [This post](https://dev.to/desoga/javascript-object-vs-json-demystified-494j) which should help to clarify the difference between Javascript objects and JSON, and then decide whether you need to rephrase your question.

---

<div class="post-metadata">

**Author:** ![Eintracht00](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@Eintracht00](https://discourse.nodered.org/u/Eintracht00)\
**Post date:** [8 March 2021 07:24 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241/3 "2021-03-08T07:24:31Z")

</div>

i know the difference between them, but that is not answering my question..

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 March 2021 07:26 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241/4 "2021-03-08T07:26:34Z")

</div>

> [@Eintracht00](#):
>
> Hey is there a way to search in a JSON data for a property

The switch can test for a key

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/31a85d7779706bece3d145476f4a6417ddb76828.png)

but it wont search for a key in sub properties.

If you want tot search full object and all sub properties, you can achieve that easily with a function node

---

<div class="post-metadata">

**Author:** ![Eintracht00](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@Eintracht00](https://discourse.nodered.org/u/Eintracht00)\
**Post date:** [8 March 2021 07:44 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241/7 "2021-03-08T07:44:26Z")

</div>

ok key works well, if i go for sub properties i just need to go for the next higher part in property and it works. thanks for the answer. You can close the topic so 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 March 2021 08:06 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241/8 "2021-03-08T08:06:25Z")

</div>

So it isn't JSON (which is a string), it is a javascript object.

---

<div class="post-metadata">

**Author:** ![Eintracht00](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@Eintracht00](https://discourse.nodered.org/u/Eintracht00)\
**Post date:** [8 March 2021 08:25 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241/9 "2021-03-08T08:25:14Z")

</div>

it is JSON, i get it from device Dashboard. i split it into objects after "\n", so its JAVA Objects.  
If ur just here colin to show how clever u are, stop answering. i had a question and steve helped me well. ur just giving not helpful information for exactly that question.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 March 2021 08:44 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241/10 "2021-03-08T08:44:27Z")

</div>

The point is that the question was not clear. You asked how to 'search in a JSON data for a property', which implies that you want to search a string, whereas what you wanted to do was to access a property in a javascript object.

> [@Eintracht00](#):
>
> so its JAVA Objects.

Javascript. Java is very different again.

---

<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:** [22 March 2021 08:44 UTC](https://discourse.nodered.org/t/search-for-json-property-swtich-if-match-not-match/42241/11 "2021-03-22T08:44:47Z")

</div>

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