I'm working on an external API.
They want JSON as a string for a GET request in a query param.
The problem with Ruby is that it treats JSON as a string and escapes quotes, so we end up sending:
"{\"api_key\":\"9e4b33422adb-3832c7-41379-b2f31-8fc295aefb8c8\",\"ip\":\"184.61.23.239\"}
Instead of {"api_key":"9e4b33422adb-3832c7-41379-b2f31-8fc295aefb8c8","ip":"184.61.23.239"} as their system is expecting.
Any idea the best way to handle formatting our JSON to match their criteria?
You could use JSON.parse, i.e.,
JSON.parse("{\"api_key\":\"9e4b33422adb-3832c7-41379-b2f31-8fc295aefb8c8\",\"ip\":\"184.61.23.239\"}")
returns
{"api_key" => "9e4b33422adb-3832c7-41379-b2f31-8fc295aefb8c8","ip" => "184.61.23.239"}
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