# How to encode and decode string using HUBL

**URL:** <https://community.hubspot.com/t/how-to-encode-and-decode-string-using-hubl/14483>\
**Category:** CMS Development\
**Created:** [May 22, 2019, 9:20am UTC](https://community.hubspot.com/t/how-to-encode-and-decode-string-using-hubl/14483 "2019-05-22T09:20:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hubmonks](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hubmonks/32/35608_2.png) [@Hubmonks](https://community.hubspot.com/u/Hubmonks)\
**Post date:** [May 22, 2019, 9:20am UTC](https://community.hubspot.com/t/how-to-encode-and-decode-string-using-hubl/14483/1 "2019-05-22T09:20:48Z")

</div>

How to encode and decode string using HubL same as atob() and btoa() fucntion does in Javascript.

---

<div class="post-metadata">

**Author:** ![stefen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stefen/32/29274_2.png) [@stefen](https://community.hubspot.com/u/stefen)\
**Post date:** [May 23, 2019, 11:48am UTC](https://community.hubspot.com/t/how-to-encode-and-decode-string-using-hubl/14483/2 "2019-05-23T11:48:59Z")

</div>

@Hubmonks I don’t see anything in the HubSpot HubL Documentation, however, you could try the following filter which works in certain Jinja environments (hubl was originally based on jinja):

```auto
{{ encoded_string|b64decode }}
{{ decoded_string|b64encode }}

```

It most likely won’t work but it’s worth a shot. Otherwise, you could print the HubL string into a script tag and use the js function on the client side.

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [April 27, 2023, 1:04pm UTC](https://community.hubspot.com/t/how-to-encode-and-decode-string-using-hubl/14483/3 "2023-04-27T13:04:32Z")

</div>

For this record this does work, thanks @stefen 👍

---

<div class="post-metadata">

**Author:** ![stefen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stefen/32/29274_2.png) [@stefen](https://community.hubspot.com/u/stefen)\
**Post date:** [April 27, 2023, 1:05pm UTC](https://community.hubspot.com/t/how-to-encode-and-decode-string-using-hubl/14483/4 "2023-04-27T13:05:54Z")

</div>

nice, good to know!

---

<div class="post-metadata">

**Author:** ![SStrachan1](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@SStrachan1](https://community.hubspot.com/u/SStrachan1)\
**Post date:** [June 26, 2023, 12:42pm UTC](https://community.hubspot.com/t/how-to-encode-and-decode-string-using-hubl/14483/5 "2023-06-26T12:42:33Z")

</div>

@stefen @piersg  
I am trying to decode a URL and getting this error. Any ideas on what’s wrong?  
input byte array has wrong 4-byte ending unit

```lia-code-sample
{% set encoded_url = request.query %}
<h5>encoded: {{ encoded_url }}</h5>

{% set decoded_url = encoded_url|b64decode %}
<h5>decoded: {{ decoded_url }}</h5>

```
