Beginner Clojurist here. I'm trying to parse a JSON file using Clojurescript and the cljs-http
library. I have strange behaviour using the following function:
(defn make-remote-call [endpoint]
(go (let [response (<! (http/get endpoint))]
(js/console.log (:body response)))))
This will print the json file to the console but I'll get this error message:
XML Parsing Error: not well-formed
Location: file:///***U2328710-data.json
Line Number 1, Column 1:
Things I've tried:
- the JSON file passes http://jsonlint.com with success, but https://jsonformatter.curiousconcept.com/ parses the file and says
Error:Invalid encoding, expecting UTF-8, UTF-16 or UTF-32.[Code 29, Structure 0]
- same issue when I deploy on Apache server. My .htaccess file is correctly set up to send content-header to application/json and charset to utf-8 (though I've read I should be sending UTF-8 in caps, haven't been able to do that)
- I can parse an XML file with the same function without a problem
- I can parse the same JSON file without a problem using the deprecated
js/XMLHttpRequest
Running out of ideas - can someone help please? I wonder if cljs-http doesn't understand it's a json file, can I force it / maybe override headers? Thanks,