Reputation: 537
The previous ConceptNet 5.4 API version returns plain text JSON format (http://conceptnet5.media.mit.edu/data/5.4/c/en/library).
Does someone familiar with the new ConceptNet 5.5 API? Why the query returns html source and not plain text like previous version (http://api.conceptnet.io/related/c/en/library)? I didn't find option to select the plain text JSON format.
Therefore, this Java code is not usable with the new version.
JsonReader jsonReader = Json.createReader(new URL("http://conceptnet5.media.mit.edu/data/5.4/c/en/library").openStream());
Upvotes: 2
Views: 608
Reputation: 3838
The format of the API response depends on the Accept:
header that your client sends. (I found this behavior really convenient when Django REST Framework does it, so I implemented it in ConceptNet's API code.) The default response format is JSON.
If you run curl http://api.conceptnet.io/related/c/en/library
at the command line, for example, you will see plain, un-indented JSON. If you go there in a Web browser, it's indented and wrapped in HTML so it can be syntax-highlighted and linked. The difference is that the Web browser sends the header Accept: text/html
.
I think it's a bug in the JsonReader you're using that it's explicitly sending Accept: text/html
and yet it's expecting a JSON response, not HTML. See if you can work around it by configuring the headers it sends.
(If getting the HTML is unavoidable, note that the plain JSON is also present in the HTML, within the <script type="application/ld+json">
tag.)
Upvotes: 1