Search code examples
javajsongolinkedin-api

How can we prepare "valid JSON" from Linkedin Share API


Recently, from our log, we saw this:

httpRes status received 400 Bad Request for this linkedinToken AQUz3sCODu312rHNtNfuns3awy0xoUxxxxxxxxxxx.
 With Request: {"content":{"submitted-url":"http://mpg.smh.re/2Ra","title":"Gestionnaire sinistre H/F − Belgique ","description":"Responsable de la gestion de dossiers sinistres dans leur intégralité,
 vous serez en contact avec de nombreux interlocuteurs (compagnies 
d’assurances, clients et bureaux locaux).","submitted-image-url":"http://www.morganphilipsexecutivesearch.com/wp-content/uploads/2014/09/fyte-smarpshare.jpg"},"visibility":{"code":"anyone"},"comment":"FYTE, cabinet de recrutement spécialisé recrute pour l’un de ses clients situé en Belgique un Gestionnaire sinistre H/F."}.
 Response body: {
  "errorCode": 0,
  "message": "Couldn't parse Json body: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: java.io.StringReader@42ea5bc1; line: 1, column: 187]",
  "requestId": "0GYQWP14U9",
  "status": 400,
  "timestamp": 1423490252325
}

```

LinkedIn API said that it couldn't parse JSON body. Our doubt is that either character "é" or "’" is not handled by JAVA JSON parser.

My question is that is there any other special/unicode characters that we should be aware of? Because this JSON body was marshaled by Go's built-in.

UPDATE: I recently discovered that "line feed" ("CTRL-CHAR, code 10") is the key to this issue. "Line feed" character appears after "...leur intégralité,". My question now is that why doesn't Go built-in JSON marshaller handle that


Solution

  • JSON can cope with Unicode characters ... provided that they are properly encoded.

    However the error message says:

    Illegal unquoted character ((CTRL-CHAR, code 10))
    

    which seems to be saying that you have a control character in the JSON. The JSON syntax states that unescaped control characters are not permitted in strings.

    Now if we assume that 10 is decimal, then it is a newline character. So I would look for a raw newline within the JSON about 187 characters from the start.


    My question now is that why doesn't Go built-in JSON marshaller handle that.

    Two possibilities:

    • it is a bug, or
    • you are not using it correctly.