JSON parse error: Unexpected character ('n' (code 110)): was expecting comma to separate Object entries


#1

We have a test where we pass a JSON object to an endpoint object. The object created in katalon studio passed the JSON object right on through to the endpoint

This test is passing when run in Katalon 6.3.0.rc7, but if we run it in Katalon 6.3.3 it fails with the error message

JSON parse error: Unexpected character ('n' (code 110)): was expecting comma to separate Object entries

To be clear, the enpoint of our microservice is throwing this error, and Katalon fails the test when the api call returns a 400 instead of a 200…

To me it looks like the message being sent to the endpoint is not identical. It seems extra characters are being added to the request object before it leaves Katalon.
Is anyone experiencing this problem?
Is there a way to have the request object printed out so I can see what is actually being sent?


#2

You can see requests and their properties in the DevTools Network panel.

You should consider upgrading to the latest release.


#3

what else would you expect?
i suggest to add a verification (or two) in katalon before any attempt to parse the response:

  • response code 200
  • response is json

#4

The problem is that the test passes with a 200 in 6.3.0, but i get a 400 in 6.3.3.
Nothing else changes. The test does not change, so I would not expect a different result


#5

it’s not a request that goes through the browser.
It goes from katalon directly to the microservice.

Upgrading might be an option down the road, but my company is currently using 6.3.3 across the board.


#6

My bad. I test all my services through the browser and keep forgetting how Katalon WS calls are made.

Wireshark? Fiddler?


#7

this is why I suggested that always to check for response code, before to attempt to parse the json, to avoid code crashes.

Now, to the issue … how does the URL of your API request looks like? Does contain special (escaped) characters?
If it is a POST … can you show us the body too?
Can you share also the .har file generated by the request?


#8

The URL does not have any special characters,

/api/ws-server/message

It is a POST, it does have escaped characters, and the body looks like below. (it is a constructed message in multiple layers, hence the various escapes)

{
“topic”: “/topic/service/device/message”,
“message”: “{ “devices”: [{ “deviceIndicator”: “pts”, “deviceDuiIndicator”: “pts-gui”, “deviceProperties”:{ “DASSystemConfig”: “{ \“name\”: \“CPTS TestSystem\” }” }, “status”: { “deviceIndicator”: “pts”, “status”: “READY”, “statusProperties”:{ “DASSystemState”: " { \“errorSignal\” : \“OK\”, \“doNotLoad\”: \“true\” }” }, “level”: “READY” } } ], “timestamp”: “2019-12-03T14:02:07.971Z”, “messageId”: “e9265edb-c3e8-42e0-96c9-a826b418cd41”, “messageClass”: “DALDeviceInfoV1” }"
}

Sending this exact message through to the endpoint using the Object Repository results in a 200.
But calling the endpoint from the test using WS returns the 400

WS.sendRequest(findTestObject(‘websocket mock/send message’, [(‘url’) : GlobalVariable.WS_MOCK_URL, (‘message’) : msg]))

I don’t have a .har file


#9

carefully check the content of this variable.
the ‘n’ in the error response may indicate you have somewhere an undesired ‘not new line character’ (not properly escaped)

how is this variable produced? it is grabbed by a previous request or created in the script?

LE: to produce reliable Json bodies from the script code, a better approach is to use groovy SimpleTemplateEngine, instead of abusing escape’s (if parametrization is desired)

http://docs.groovy-lang.org/docs/next/html/documentation/template-engines.html

For simple plain bodies, use triple double quoted strings (Gstrings) (also Triple-single-quoted string may work for your case):
http://docs.groovy-lang.org/latest/html/api/groovy/lang/GString.html

see: |Neither double quotes nor single quotes need be escaped in triple-double-quoted strings.|


#10

@Ibus

character 110 == ‘n’ not 10 = \n


#11

@Russ_Thomas thx for correction, i amended:

‘not new line character’ 

#12

The content of the message is posted above. It does not vary.
If we had extra escape characters in there, or the json was not properly formatted, would it not fail with both versions?


#13

I agree. It certainly sounds like there’s a parser issue between the two versions. However…

If that were the case, there would have been MANY similar reports from many users. There aren’t (weren’t) any, to my knowledge.


#14

it may not.
as far as i know there were various updates with regards how the escaping is working (in url’s, in bodies) during various versions … so better use proper and easy readable ways to produce your bodies.
will help you to reduce flakiness


#15

As it looks like you have “ and not " in your response. that would not be valid JSON


#16

Where did you see that?


#17

I did Copy and past the json above to http://json.parser.online.fr/ to validate it, and it did say it right away :wink:


#18

Take care with copy and paste from the forum. The forum ALWAYS messes with quotes - it’s very annoying.

Using the Crockford original, it’s perfectly valid.


#19

@Jens.gr

that’s why I always ask for properly formatted code from the author source.
once pasted as regular text or quote-block, > 50 % of the original code format is destroyed.

and you copy from the forum and paste again somewhere > another source for errors. and so on …


#20

Oh damn, good to know that messes with the sources