Filter / exists condition yields JSON parsing error

Hello!

I’m using the Twitter integration, and I’m querying for some particular tweets.
I then apply a Filter to the tweets returned, to check only tweets that contain an image.
I use an Exists condition to only continue the workflow if that condition is met.
In the case of my image, I check that the following key exists:

{{steps.trigger.event.entities.media[0].media_url_https}}`

But I’m getting the following error:

SyntaxError
Unexpected token h in JSON at position 0

The value in that key is just a string.
And since it’s a link to an image stored on Twitter, it’s a string containing a URL, which of course starts with an h.
For example, a value in that field is: https://pbs.twimg.com/media/FRCIzy0WQAEC668.jpg

Does the filter assume that the key’s value needs to be some JSON object or array? So it’s not possible to check for the existence of a value?

I haven’t been able to find the documentation on Filter to better understand how to create my exist condition. If you can point me at the right direction, I’d be grateful.
Thanks in advance for your help.

1 Like

Hi @glaforge ,

First off, welcome to the Pipedream community. Happy to have you!

You’re understanding the Filter action correctly, but just one tidbit that might solve the issue for you.

The steps.trigger.event.entities.media path won’t always exist, because not all tweets have images.

Before the data is passed into the Filter, make sure you’re safely accessing that data:

`{{steps.trigger.event.entities?.media[0]?.media_url_https}}

Now, if the steps.trigger.event.entities.media array doesn’t exist at all, instead of throwing an exception, the result will return undefined which the Filter should be able to handle.

Hope this helps!

I am having the same issue. Here is the error:

There is no undefined or missing data in this example. I’m having trouble understanding why this JSON error.

@sysadmin thanks for the screenshot, can you also share a screenshot of the value of the steps.trigger.event.body.payload?

I suspect that this particular variable is a string or some other non JSON serializable format.

If it is a string, then I suggest adding a Node.js or Python code step to convert it into JSON, then you’ll be able to use a Filter to read the individual attributes on the object.

It’s in the screenshot in Initial value. it appears to be valid JSON

{ "plainToken" : "TOKEN" }

Thanks @sysadmin , I didn’t notice that you included the initial value in the screenshot.

I can confirm this is a bug with objects as the initial value in this action.

We accept bug reports for actions here: New Pipedream Integration Request

Could you please open a bug report and link to this thread?

Also, this actions are open source so you’re free to fork our repository and modify the action directly as well.