-2

JSON is located at:

http://www.medialweb.it/corsi_ok.json

When I use the online tool:

https://jsonformatter.curiousconcept.com/

I get the following error messages:

Error:Invalid media type, expecting application/json.[Code 28,Structure 0] 
Error:Invalid encoding, expecting UTF-8, UTF-16 or UTF-32.[Code 29, Structure 0]
dubes
  • 5,324
  • 3
  • 34
  • 47
Matteo Villa
  • 47
  • 2
  • 12

4 Answers4

3

thanks @dubes

what worked for me, after doing everything! change this:

Content-type: application/json; charset=utf-8

to:

Content-type: application/json; charset=UTF-8

(caps)!

GeekKing
  • 311
  • 5
  • 11
2

Assuming: You are pasting the "url" in the jsonformatter to validate the json.

Your JSON is structurally valid.

The errors shown are related to the missing metadata about content that your service should expose. Typically the client that would consume any resources you may expose over the network might/would like to know (among other things):

  1. What type of content is being returned
  2. What is the charset / character encoding I should use to make sense of the payload. Most of the clients default to UTF-8, so in that case, this error is more of a warning, but better to explicitly mention it.

The client would look for this information in the Content-type response header.

The server/service exposing that JSON, is not setting the Content-type: application/json; charset=utf-8 in the response header, thus the tool raises the error.

Edit (Bonus tip): If you have any confusion about the content header for the json, would definitely recommend reading this question

Community
  • 1
  • 1
dubes
  • 5,324
  • 3
  • 34
  • 47
  • I set my header to "Content-type: application/json; charset=utf-8" and am still getting this same error message with this tool. – cazort Feb 18 '19 at 22:41
  • You need to use all caps: UTF-8, it's case-sensitive apparently. – cazort Feb 18 '19 at 22:41
0

use single line code in your php api file

header('Content-type: application/json; charset=UTF-8');
ssatish4u
  • 131
  • 2
  • 9
-1

I thing the JSON data exceeds the maximum number of characters so, the error showing, if you partially valid the json file , the error will not show.

  • JSON does not have a limit of maximum characters. [See this question](http://stackoverflow.com/q/1262376/1695393). The JSON is valid. The tool for validation may have limits on characters it can validate successfully, though I do not see any mention of the limit in the error message nor in the tool. If you have any reference to the limits enforced by the tool, please add them to your answer. – dubes Sep 14 '16 at 13:43