Following a HTTP request, I get a JSON with loads of fields. The content of one of the fields that I need is encoded in base64. I have NO idea how to decode it! I am a noob in coding, so I have no idea how to use javascript or other to decode the base64. I was hoping maybe to find an API to decode the base64 field, but apart from it being a ridiculous workaround, I also didn’t find any such api services.
Can anybody please help me how to get this done?
I’ve just subscribed for the trial in the hope I can get n8n to work with my basic programming mindset, but minimal coding capacity. Please help me over this hurdle
Decoding base64 is a bit tricky in n8n, but possible. You’d need to run a bit of JS to do so. The basic approach is for example described here, in a workflow it would look like so:
In this example I am using the Function Item node which allows running arbitrary JS code. The example code adds a new memo_text field with the decoded value of each memo_base64 field in your transactions array:
for (transaction of item.transactions) {
// Create a buffer from the base64 string
let bufferObj = Buffer.from(transaction.memo_base64, "base64");
// Encode the Buffer as a utf8 string
let decodedString = bufferObj.toString("utf8");
// Write the result in a new memo_text field
transaction.memo_text = decodedString;
}
return item;
You can also just double click on the Function Item node in my example workflow above to see it (or simply copy the node directly into your own n8n canvas).
If you are struggling to decode a base64 field from json and have minimal coding experience there is a simple solution you can use without writing any code
you can try using an online tool like base64 to pdf converter from ilovepdf2 all you need to do is copy the base64 string from your json paste it into the tool and it will convert it into a readable pdf or text file depending on the content
this way you can see the data clearly without dealing with javascript or other programming and it works perfectly for images documents or text stored in base64
it should help you get past this hurdle quickly and continue working with your json data without any coding headaches