I’m pulling a response from an API and receiving:
response:
job:
unit_count: "1"
slug: Answers
lc_tgt: ja
body_tgt: !binary |
5Zue562U
lc_src: en
body_src: Answers
job_id: "1948888"
opstat: ok
That body_tgt value should be a couple Japanese characters(回答), but they are being converted for safe shipping. I’m in 1.8.7, so I can’t force_encoding. Is there a way to unpack() them?
That appears to be a YAML document, not JSON, using YAML’s binary data language (which in turn uses base64 encoding).
Ruby’s built in YAML parsing library should be able to parse the data for you:
In order to produce YAML with UTF-8 directly embedded, instead of escaped as binary objects, you can use ya2yaml, “yet another to_yaml” implementation, which can produce output encoded as UTF-8. Install the
ya2yamlgem, and then invoke it as: