Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clj-http not returning JSON

I am trying to read JSON from a REST resource using clj-http version 2.2.0 but whatever I do I get the result as a string.

While debugging, I stripped down what I'm doing to this request to a static JSON document on my webserver on https://nym.at/test.json:

{"foo":1,"bar":"baz"}

I run the following code in the REPL (client bound to the namespace clj-http.client):

(client/get "https://nym.at/test.json" {:as :json :insecure? true})

The result I get is (pritty printed manually):

{:status 200,
 :headers {"Server" "Apache/2.4.18 (Debian)",
           "Upgrade" "h2,h2c",
           "Content-Type" "application/json",
           "Content-Length" "22",
           "Strict-Transport-Security" "max-age=31536000; includeSubDomains",
           "Connection" "Upgrade, close",
           "Accept-Ranges" "bytes",
           "ETag" "\"16-532fcf29f30c6\"",
           "Date" "Mon, 16 May 2016 22:14:59 GMT",
           "Last-Modified" "Mon, 16 May 2016 22:14:27 GMT"},
 :body "{\"foo\":1,\"bar\":\"baz\"}\n",
 :request-time 637,
 :trace-redirects ["https://nym.at/test.json"],
 :orig-content-encoding nil}

Is my expectation wrong, that the {:as :json} should result in clj-http parsing the response as JSON and returing it at :body or am I doing something wrong here?

like image 942
Matthias Wimmer Avatar asked May 16 '16 22:05

Matthias Wimmer


1 Answers

Add [cheshire "5.6.1"] to your project and it will magically start working

See https://github.com/dakrone/clj-http#optional-dependencies

like image 190
Timothy Pratley Avatar answered Sep 28 '22 13:09

Timothy Pratley