# Encode string in Ruby decode it in Javascript?

**URL:** <https://www.ruby-forum.com/t/encode-string-in-ruby-decode-it-in-javascript/191671>\
**Category:** Ruby\
**Created:** [July 16, 2010, 1:41am UTC](https://www.ruby-forum.com/t/encode-string-in-ruby-decode-it-in-javascript/191671 "2010-07-16T01:41:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snouser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@snouser](https://www.ruby-forum.com/u/snouser)\
**Post date:** [July 16, 2010, 1:41am UTC](https://www.ruby-forum.com/t/encode-string-in-ruby-decode-it-in-javascript/191671/1 "2010-07-16T01:41:29Z")

</div>

As the title describe.  
I need to pass some data from the server side to the browser.  
But I cant figure out how to encode it on the server en decode using  
Javascript.

Any ideas?

---

<div class="post-metadata">

**Author:** ![snouser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@snouser](https://www.ruby-forum.com/u/snouser)\
**Post date:** [July 16, 2010, 3:43am UTC](https://www.ruby-forum.com/t/encode-string-in-ruby-decode-it-in-javascript/191671/2 "2010-07-16T03:43:45Z")

</div>

JSON

On Jul 16, 2010 8:42 AM, “Linus Oleander” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

As the title describe.  
I need to pass some data from the server side to the browser.  
But I cant figure out how to encode it on the server en decode using  
Javascript.

Any ideas?

---

<div class="post-metadata">

**Author:** ![snouser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@snouser](https://www.ruby-forum.com/u/snouser)\
**Post date:** [July 16, 2010, 11:52am UTC](https://www.ruby-forum.com/t/encode-string-in-ruby-decode-it-in-javascript/191671/3 "2010-07-16T11:52:55Z")

</div>

Michael F. wrote:

> JSON
> 
> On Jul 16, 2010 8:42 AM, “Linus Oleander” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> As the title describe.  
> I need to pass some data from the server side to the browser.  
> But I cant figure out how to encode it on the server en decode using  
> Javascript.
> 
> Any ideas?

I’m already using JSON to pass data to the client.  
But as I wrote in my first post i need to decode a string on the server  
site and decode it in the client.

I found a solution to the problem.

The unescape(); method on the client (JS)  
And on the server I used URI::escape (Ruby)
