Jira API call is failing

Sudhansu Sekhar Panda May 23, 2021

Jira API call is failing due to some special characters like (double quote, dot .... etc)
below is the exception captured in the logs.

Exception while posting to Jira: Jira exception [{"errorMessages":["Unexpected character ('\"' (code 34)): was expecting comma to separate OBJECT entries\n at [Source: org.apache.catalina.connector.CoyoteInputStream@78d2c46f; line: 1, column: 160]"]}]

can any one share the list of such character?

6 answers

2 votes
Graham Twine _Slm_ May 24, 2021

In your post you have only copied the first line of your error.

org.apache.catalina.connector.CoyoteInputStream

Tomcat should not have any knowledge of whether the JSON object is valid or not, or if it is even JSON. The Content Type and Accepts headers are used in MIME mapping.

At this point it is a call the text is just characters.

Characters in the URL can be managed from the server.xml

<Connector connectionTimeout="20000"
port="8080"
protocol="HTTP/1.1"
redirectPort="8443"
relaxedQueryChars='^{}[]|&quot;' />

In your error there is a hint `was expecting comma to separate OBJECT entries`
As you are using a POST this implies the JSON in the body of your REST call is not valid.

As @Davin Studer has mentioned use a JSON library such as Jackson or GSON

Never serialise objects using string manipulation. It will always come back and bite you.

Libraries have the ability to configure de/serialization.

The following is just an example of the many configuration properties for Jackson

mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

Can you get hold of the payload in your POST? If so check it in an online JSON parser.

This is just one of many online tools.

Graham Twine _Slm_ May 26, 2021

@Sudhansu Sekhar Panda did you manage to solve your issue?

Please update the people who were so kind as to take a few minutes out of their day to assist you.

Sudhansu Sekhar Panda May 26, 2021

Currently we are still working on it. I will share the update. Once everything is fixed.

But any ways thanks a lot for your support guys

2 votes
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 24, 2021

Are you building the JSON manually? If so I would suggest creating a object to represent your data and then use one of the many libraries out there to serialize it to JSON.

2 votes
WW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 24, 2021

@Sudhansu Sekhar Panda ,

I'm guessing that the error is happening in Json that you're passing to a POST call, and not happening in the syntax of the URI.  If it is in the URI, then that's another answer.

What I'd do first is to look at your Json and go to line 1 column 160.  If it looks like there's a special character there, then escape it.

(I don't know if it's the same for you, but at the company where I work, they block the site linked to in the previous comment.  So, I'm not sure what it says there.)

Generally, you can escape a special character with a backslash \

For example:  \" lets you have a double quote " where you may be getting the error.

In summary:

  1. Find the character causing the trouble
  2. Escape the character

I have a list of problematic characters that I search for and escape before sending a POST call.  This usually covers the problem areas, but there may be more:

  • \  -> \\
  • '  ->  \'
  • any kind of new line character  ->  \n
  • tab  ->  \t
  • weird characters that come up that are not needed  ->  zero length string ""

You don't want to replace all double quotes (if those are the problem) in the Json with \", though, since they're needed for the Json structure.  Make sure you escape only in the values (of the key:value pairs) before forming the Json.

Graham Twine _Slm_ August 27, 2023

One should really be using a library to generate the JSON. The library will have some configuration that will resolve all of the above issues and some no one here has even thought about yet.

 

USE A LIBRARY, never generate JSON in strings, it is clunky, has very poor performance and it is error prone!!!

2 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 24, 2021

Hi @Sudhansu Sekhar Panda this is problem with JSON format, so this link should give you your answer https://www.tutorialspoint.com/json_simple/json_simple_escape_characters.htm

0 votes
workingstorage_user August 23, 2023

The answer, in Python at least, is to raw the search variable, build the JSON in a string, and pass it as a json parm to the request call:

 

jql = r'( summary~"\"my literal text\"") '

payload
= {"maxResults": max_results,"jql": jql, "fields": ["*all"] } 

self.request_session.headers["Content-Type"] = "application/json"

response=requests.post(url,json=payload,headers=self.request_session.headers)



0 votes
Deian Vikov October 21, 2021

Hi,

I have the same problem. I'm escaping the double quotes within the JSON with \" but had still the same error.

I tried with  a very simple json containg in the description of an issue just one double quoute and is not working.

My goal is to have a HTML page in the description of an issue created by the API, but I'm stuck now in this problem when escaping the double quotes.

Does anyone has a solution ?

Regards

Graham Twine _Slm_ August 27, 2023

Use a JSON library!!!

Suggest an answer

Log in or Sign up to answer