Jotform json error

I have been downloading data entered by users using jotform via their api. I retrieve the results using Xojo in json. Every once in a while I get a json error (such as missing “}” ) and it crashes the program.

I’m not exactly sure what is causing the error (maybe characters the person filling out the form on jotform can enter that will screw up the json). I’m wondering, since the error doesn’t crash the jotform web site or screw up jotform’s ability to handle the data, maybe I’m handling the json data poorly.

I get the result string from my api call in a string variable “s”.

Then this is the line that crashes the program:

Dim js As New JSONItem(s.DefineEncoding(Encodings.UTF8))

I would have to say this code works most of the time, but every once in a while it just crashes.

Not exactly sure where this error is coming from - invalid character being entered by person filling out form in jotform?

Any help would be greatly appreciated.

Well first of all, if you’re getting that message, it’s an exception and it doesn’t have to crash your app. Whenever you write code that could raise an exception in the case of an error, you should wrap it in a try-catch block. In this case you would be looking for a JSONException.

When you do catch one of these, you may want to write it to disk and then try running the JSON through an online parser to tell you where the error actually is.

1 Like

I do understand using try to trap the exception to avoid the crash. Thanks for the input.

I was able to trap the error using Try and found that the json the API is pulling is throwing some errors in different places and for different records intermittently. I may run the API call several times and get the same error in the same place - and then I slightly change the number of records being pulled and the error may appear in a different record (or sometimes no error at all).

The error is always the something like this:

"72": {
				"name": "assignmentOf",
				"order": "101",
				"text": "ASSIGNMENT OF BENEFITS",
				"type": "control_head"
				100 527 k 0 527 k 0 0 504 k 0--: --: --0: 00: 01--: --: --504 k
				100 527 k 0 527 k 0 0 504 k 0--: --: --0: 00: 01--: --: --504 k
			},

Or this:

"72": {
				"name": "assignmentOf",
				"order": "101",
				"text": "ASSIGNMENT OF BENEFITS",
				"type": "control_head"
				100 527 k 0 527 k 0 0 558 k 0--: --: -- --: --: -- --: --: --558 k
			},

Here is the error message:

Error: Parse error on line 17882:
... "control_head"				100 527 k 0 527 k 0 
----------------------^
Expecting 'EOF', '}', ':', ',', ']', got 'NUMBER'

Is there something that can intermittently corrupt data transmission?

I am using another API with another web site and never seem to get an API error. Confused as to what actually is happening here.

The error isn’t wrong, that’s not valid JSON. It looks like something is inserting some sort of control packet (or maybe a status readout of a download?) into the middle of the JSON.

Sounds like breaking this up into smaller segments will help. Thanks, Kem.

Your problem is these lines. Somehow they’re ending up in the middle of your JSON and they shouldn’t be.

How are you retrieving the JSON from the API? URLConnection inside a Xojo app or are you using curl?

I am using curl to retrieve the JSON via a shell command.

That’s curls status readout, as I suspected. Give it the switch to suppress that.

But why not use URLConnection?

1 Like

URLConnection? OK, this is something I have to check into. Does this replace the need for curl?

I was looking for the curl switch to suppress the status and am having trouble with it. I’m getting an error with -s. Do you know the format for that?

Thanks.

Yes, you wouldn’t need curl.

-s should do it. What error?

I was using -X and -s together which didn’t work. I switched it to just -s and it worked ok.

Just wanted to say thanks. :wink:

1 Like