Access to a specific value of an object from previous Node

Hi n8n team!

I’m trying to access to some previous JSON data (image.url) from an HTML Extract Node. Here is the code below :

But I cannot figure why I cannot access to it…

When I’m trying in this tool : https://jsonpath.com/

It seems ok when I’m trying : $.image.url (I can get the url). But it’s not the case in n8n…

I know that I’m missing something but I cannot understand why.

Please, could you help me to figure out where the problem comes from?

Thanks a lot!

Welcome to the community @MB1!

It is actually best to use drag and drop to create simple expressions. To do that, hover with the mouse over the value you want to link and then drop it on the parameter you want to use the value on. That will then always create a valid expression.

The issue in your case is, that you add dots between the different values that should not be there. You can either use dot-notation or the ['value'], but you can not use both at the same time. That will mess things up. If you remove the dots it should work fine. So in your case use the following expression:

{{ $json['urlImage']['image']['url'] }}

or

{{ $json.urlImage.image.url }}

Hope that helps!

Thanks a lot, Jan for your reply.

I tried before, but this is not working…

Here is the object if you have an idea…

Thanks a lot!

If you look at the way the data is being presented in the urlImage field of the previous node, it’s being output as a string rather than JSON.

If you want to access the keys inside of that JSON, then it needs to be output as a JSON object.

Hint: Did you mistakenly insert a JSON.stringify somewhere?

That’s why I thought Joel.

No there is not json.stringify… Before this node, I’ve got an Extract HTML Node.

How to convert this string in JSON? I’ve tried JSON.stringify, but I’m not sure how to write it… Do you have an idea to help me please?

Thanks :slight_smile:

Ah great find @joeldeteves! Did not see that it is a string.

In this case @MB1, you need JSON.parse which does the exact opposite of JSON.stringify:

{{ JSON.parse($json.urlImage).image.url }}
1 Like

This so great Jan!

Thanks a lot for your help. It’s working fine!

Keep on the (very) good work on n8n, it’s an incredible tool!

1 Like

You are welcome. Great that it helped ! Have fun!

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