I have users contact info saved as a vCard within a JSON object. I’d like to access this and extract the elements (Name, Tel, Email etc) into JSON elements to that I can access/reference them individually within n8n.
I’ve found a few resources online to support with this - like this npm library (https://www.npmjs.com/package/vcard) and whilst I read that it is possible to use external libraries with n8n - I’m not sure if it is whilst hosting my instance on n8n Cloud.
Would love to hear from other n8n user who either know how to do this, or have accomplished something similar via any means that could sit in n8n.
Hi @Felix_is_stuck, this sounds like quite a challenge to build yourself without a designated node. Luckily, this problem has already been solved, for example here:
You could for example use such parser code in a Function node. Here is an example using the above parser and then reading the full name (which just takes the first value from the FN field) as well as the home address (which performs a bit of filtering for demo purposes):
The function as pasted from your example above is also failing if I pass a different vCard to it - one that doesn’t have a ‘Home Address’ set, is that the expected behavior?
Ideally it would output all of the variables stored in the vCard, and only if they are present.
Ah, I didn’t add any checks as to whether the respective element exists in my example code. So when trying to extract a non-existing field, you’d indeed get an error (probably something like Cannot read property '0' of undefined).
I don’t know much about vcards and all the different formats they could have, but have added some checks using the ternary operator in the below example: