Search code examples
ruby-on-railsrubyjsonpostgresqljsonb

Save ASCII value to jsonb / postgres / ruby


I need to save this value:

"O\xB70\x8Bk\xA3\x82\t\x9At\xD8\"\x1Cu)\xAF"

In a jsonb column in a postgres db like this:

value = { :body_hash => "O\xB70\x8Bk\xA3\x82\t\x9At\xD8\"\x1Cu)\xAF", :another_prop = "same value" }

I get the following error:

"\xB7" from ASCII-8BIT to UTF-8

I could just force encode to UTF-8 but I don't want to do that. I just want to save the exact value above.

How do I do that? Thanks!


Solution

  • I could not save the value due to the encoding settings of my db. I converted the value to hex and saved that value instead.