"does list x contain" block does not find object

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

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

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

1 Like

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

1 Like

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

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

1 Like

GitHub https://github.com/thunkable/thunkable-issues/issues/697#issue-718245622

1 Like

Mind marking this one as the solution? :wink:

1 Like

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.

1 Like

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

1 Like

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

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

1 Like

So your delimiter is }”,”{

Right?

1 Like

Not mine, thunkables.

1 Like

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

.

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.

1 Like