MB1
November 12, 2022, 7:13pm
#1
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!
jan
November 12, 2022, 7:32pm
#2
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!
MB1
November 12, 2022, 9:15pm
#3
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?
MB1
November 12, 2022, 9:52pm
#5
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
jan
November 12, 2022, 10:44pm
#6
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
MB1
November 12, 2022, 11:00pm
#7
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
jan
November 13, 2022, 9:06am
#8
You are welcome. Great that it helped ! Have fun!
system
closed
November 20, 2022, 9:07am
#9
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.