# "does list x contain" block does not find object

**URL:** https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402
**Category:** Questions about Thunkable X
**Created:** [October 4, 2020, 3:50pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402 "2020-10-04T15:50:54Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)
#### Post date: [October 4, 2020, 3:50pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/1 "2020-10-04T15:50:54Z")

</div>

Am I missing something or should the “does list x contain” block be able to find an identical object within the list?

My ultimate goal is to determine if an object I just created already exists in my Firebase Realtime Database list. If it doesn’t exist, I want to add it. If it does exist, I do not want to add it. I should be able to do something simple like:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/3/93e521ca9d54b8b1c00dbb167f14dd1de145d4a9.png)

Unfortunately, the “does list contain” block returns a false when the list contains objects.

To test the issue, I created 3 scenarios to test the “does list x contain” block. The first scenario uses a simple list of character values. The “does list x contain” block finds the match for value “b”. The second scenario uses a list of objects (such as a list from a Firebase Realtime Database). “does list x contain” block returns a false, even though the exact object appears in the list. The third scenario converts the objects to JSON text, effectively creating another list of strings. In this third scenario, the “does list x contain” block returns a true value.

So it appears that the “does list x contain” block works correctly for text, but not for objects.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/c/4c9224f3f35a1303a068881f9ba0550d50d7bd79.png)

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/e/6e1574560bf1099654b1a8333f214d6932b0105d.png)

And yes, for local variables, I could do the awful workaround to convert all object to JSON strings before inserting into a list. That solution does not work for JSON lists on Firebase or from WebAPI, etc.

Of course, here is a project link: [Thunkable](https://x.thunkable.com/copy/521a36462a3cbbfb922a829d066fcce8)

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [October 4, 2020, 4:15pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/2 "2020-10-04T16:15:31Z")

</div>

Try blocks in this order. I think you may not be working with the data correctly for this process.

Generate Json from → create list → create object(s)

Create a list of objects

Generate a Json from the list

---

<div class="post-metadata">

### Author: ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)
#### Post date: [October 4, 2020, 4:31pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/3 "2020-10-04T16:31:44Z")

</div>

I’m not sure if I understand your suggestion. But I think it is clear from your suggestion that I didn’t explain my ultimate goal, vs. the code demonstrating the issue.

My ultimate goal is to determine if an object I just created already exists in my Firebase Realtime Database list. If it doesn’t exist, I want to add it. If it does exist, I do not want to add it. I should be able to do something simple like:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/3/93e521ca9d54b8b1c00dbb167f14dd1de145d4a9.png)

Unfortunately, the “does list contain” block returns a false when the list contains objects.

---

<div class="post-metadata">

### Author: ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)
#### Post date: [October 9, 2020, 3:41pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/4 "2020-10-09T15:41:09Z")

</div>

GitHub [https://github.com/thunkable/thunkable-issues/issues/697#issue-718245622](https://github.com/thunkable/thunkable-issues/issues/697#issue-718245622)

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [October 9, 2020, 9:43pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/5 "2020-10-09T21:43:37Z")

</div>

Mind marking this one as the solution? 😉

> <https://github.com/thunkable/thunkable-issues/issues/697#issuecomment-706410207>
>
> \### Platform
> Thunkable X blocks
> 
> \### Issue/Request Origin
> https://community.…thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/3?u=drted 
> 
> 
> \### Steps to Reproduce
> My ultimate goal is to determine if an object I just created already exists in my Firebase Realtime Database list. If it doesn’t exist, I want to add it. If it does exist, I do not want to add it. I should be able to do something simple like:
> 
> \### Project Link
> Link to a project copy that shows this behaviour. This is important because most times we cannot reproduce the issues reported just with the list of steps, so please do provide this.
> 
> !\[image\](https://user-images.githubusercontent.com/66176281/95603315-edc51900-0a0a-11eb-93fa-71f073f5c6e7.png)
> 
> Unfortunately, the “does list contain” block returns a false when the list contains objects.
> 
> To test the issue, I created 3 scenarios to test the “does list x contain” block. The first scenario uses a simple list of character values. The “does list x contain” block finds the match for value “b”. The second scenario uses a list of objects (such as a list from a Firebase Realtime Database). “does list x contain” block returns a false, even though the exact object appears in the list. The third scenario converts the objects to JSON text, effectively creating another list of strings. In this third scenario, the “does list x contain” block returns a true value.
> !\[image\](https://user-images.githubusercontent.com/66176281/95603341-fcabcb80-0a0a-11eb-852b-d73213bfaf2d.png)
> !\[image\](https://user-images.githubusercontent.com/66176281/95603353-ffa6bc00-0a0a-11eb-9a6a-6fbd51d1a940.png)
> 
> So it appears that the “does list x contain” block works correctly for text, but not for objects.
> 
> \### Expected Behavior
> Return TRUE from Does List Contain when a matching object is contained in the list
> 
> \### Actual Behavior
> Returns false

---

<div class="post-metadata">

### Author: ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)
#### Post date: [October 9, 2020, 9:52pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/6 "2020-10-09T21:52:37Z")

</div>

An interesting solution. But not all JSON lists are created in thunkable. Many come from WebAPIs, Firebase Realtime Database, etc. My examples are for illustrative purposes so the contents of the JSON are explicit.

How would you implement your solution reading a 7 level JSON tree from a Firebase database short of deconstructing the entire tree?

My work around currently is a For Each loop. It works, but that doesn’t mean the block doesn’t have an obvious bug.

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [October 9, 2020, 10:16pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/7 "2020-10-09T22:16:14Z")

</div>

Nope. But they’re all made in using the same syntax aren’t they?. Each should be separated by },{ right?

---

<div class="post-metadata">

### Author: ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)
#### Post date: [October 9, 2020, 10:40pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/8 "2020-10-09T22:40:10Z")

</div>

They should be, I agree.

Here’s the hitch. I added a Get JSON from Object block and here is what is in MyList  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/d/adf58493a7032519dac7cdb2eeda83a49d752c5a.png)

You will see that each element of the list is stored as a string(quotes outside the {}). Perhaps that is the origin of the issue.

Despite a variety of work arounds, from an end user perspective, if I add an element to a list, a the “does list x contain” block should be able to find the element I added. The end users shouldn’t have to understand the nuances of JSON and list parsing, cuz that kinda defeats the purpose of no-code programming, right? 😬

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [October 9, 2020, 10:47pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/9 "2020-10-09T22:47:49Z")

</div>

So your delimiter is }”,”{

Right?

---

<div class="post-metadata">

### Author: ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)
#### Post date: [October 9, 2020, 10:48pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/10 "2020-10-09T22:48:40Z")

</div>

Not mine, thunkables.

---

<div class="post-metadata">

### Author: ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)
#### Post date: [November 29, 2020, 2:03pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/11 "2020-11-29T14:03:36Z")

</div>

With no movement on this issue from Thunkable, I have once again built my own replacement for the Does List Contain function

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/9/09d071e90ff7ff824b82f4647e6a7bbc54690065.png) .

The first check is a bit of a hack which could have problems with nested object. But it is a quick search for an exact match of the JSON for the requested object within the text of the list. If all of the properties of the SearchFor object are in the same order as the object in the list, this will indicate a match.

The nested loops make a more forgiving search, allowing for the object properties to appear in a different order. Again, if there are nested objects with properties in a different order, it won’t match up. The way to make this search work most effetively and reliably is to follow the lead of Firebase and create objects with the properties in alphabetical order.

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 12:20pm UTC](https://community.thunkable.com/t/does-list-x-contain-block-does-not-find-object/873402/12 "2024-11-08T12:20:06Z")

</div>


