clj-http not returning JSON
Asked Answered
O

1

6

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?

Outsize answered 16/5, 2016 at 22:27 Comment(0)
K
11

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

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

Karp answered 16/5, 2016 at 22:50 Comment(1)
Thanks, that worked. I must have missread the documentation as I thought cheshire is a dependency and therefore expected leiningen to load it automatically.Outsize

© 2022 - 2024 — McMap. All rights reserved.