# Search in a Json with two criteria

**URL:** <https://discourse.nodered.org/t/search-in-a-json-with-two-criteria/51807>\
**Category:** General\
**Created:** [3 October 2021 20:14 UTC](https://discourse.nodered.org/t/search-in-a-json-with-two-criteria/51807 "2021-10-03T20:14:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zamzon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zamzon/32/15521_2.png) [@zamzon](https://discourse.nodered.org/u/zamzon)\
**Post date:** [3 October 2021 20:14 UTC](https://discourse.nodered.org/t/search-in-a-json-with-two-criteria/51807/1 "2021-10-03T20:14:16Z")

</div>

Hi  
I need help searching in a json file where two criteria must be met before proceeding

I need it to proceed when only Device\_code and box\_number is the same, as it is now it proceed when only the box\_number is meth and it dosen 't care about the device\_code.  
Hope someone can help me.

```auto
msg.xml = msg.payload.DeviceExport.DeviceDetails.find((el => el.DeviceInfo[0].$.device_code === devicecode) && (el => el.DeviceInfo[0].$.box_number === bn))

```

---

<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:** [3 October 2021 20:23 UTC](https://discourse.nodered.org/t/search-in-a-json-with-two-criteria/51807/2 "2021-10-03T20:23:05Z")

</div>

Without seeing data I can only guess...

```auto
msg.xml = msg.payload.DeviceExport.DeviceDetails.find(el => el.DeviceInfo[0].$.device_code === devicecode && el.DeviceInfo[0].$.box_number === bn)

```

---

<div class="post-metadata">

**Author:** ![zamzon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zamzon/32/15521_2.png) [@zamzon](https://discourse.nodered.org/u/zamzon)\
**Post date:** [3 October 2021 20:34 UTC](https://discourse.nodered.org/t/search-in-a-json-with-two-criteria/51807/3 "2021-10-03T20:34:32Z")

</div>

Thanks, it looks like it did the job 🙂

---

<div class="post-metadata">

**Author:** ![zamzon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zamzon/32/15521_2.png) [@zamzon](https://discourse.nodered.org/u/zamzon)\
**Post date:** [3 October 2021 20:40 UTC](https://discourse.nodered.org/t/search-in-a-json-with-two-criteria/51807/4 "2021-10-03T20:40:00Z")

</div>

Do you know if it is possible to setup an error message if the criteria is not meth?

---

<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:** [3 October 2021 20:55 UTC](https://discourse.nodered.org/t/search-in-a-json-with-two-criteria/51807/5 "2021-10-03T20:55:38Z")

</div>

You could test if `msg.mxl == null` then call `node.error("not found", msg);`

---

<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:** [2 December 2021 20:56 UTC](https://discourse.nodered.org/t/search-in-a-json-with-two-criteria/51807/6 "2021-12-02T20:56:13Z")

</div>

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