I'm using the Locu API and I've currently got the results from an HTTParty request into a ruby hash called data.
I've tried to call data.to_json, and this puts backslashes in my hash:
data.to_json
=> "{\"meta\":{\"limit\":25,\"cache-expiry\":3600}
Somebody else posted the same problem that was solved as follows:
puts data.to_json
Unfortunately, that does not alter my hash at all. Any ideas?
I've tried to call data.to_json, and this puts backslashes in my hash:
Two things: The output of that is not a hash. It's a string representing your Hash in JSON. Second, the backslashes are ok. It's only to disambiguate the double-quotes from the leading and trailing double quotes.
Instead of
data.to_json
do
puts data.to_json
Which will print as you expected:
=> {"meta":{"limit":25,"cache-expiry":3600}
It is working as intended.
What you've done is serialize a hash into a JSON String, used for passing data around via HTTP or something similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With