Including json string in url encoded string (Rails)
2 answers
Use CGI.escape , not URI.encode / escape. URI.encode will not go outside the brackets of JSON arrays.
emails = '{"list_1":[{"Jim":"jim@gmail.com"},{"Joe":"joe@gmail.com"}]}'
> URI::encode(emails)
=> "%7B%22list_1%22:[%7B%22Jim%22:%22jim@gmail.com%22%7D,%7B%22Joe%22:%22joe@gmail.com%22%7D]%7D"
> CGI.escape(emails)
=> "%7B%22list_1%22%3A%5B%7B%22Jim%22%3A%22jim%40gmail.com%22%7D%2C%7B%22Joe%22%3A%22joe%40gmail.com%22%7D%5D%7D"
ruby - what's the difference between URI.escape and CGI.escape - stack overflow
0
source to share