JSON parse error when .NET SDK returns results


Whenever I execute a N1QL query using the .NET SDK, the result that comes back from the Bucket.QueryAsync method always contains an error similar to:

Unexpected character encountered while parsing value: {. Path ‘results’, line 6, position 1.

The HttpStatusCode property in the Result object is BadRequest and the Source property inside the Exception property is NewtonSoft.Json, however, the Errors collection is empty.

If I take that same query and execute it within the Couchbase admin console, the query returns the data I expect.

Also, is there a way to find out what exactly is coming back from the server that Json can’t seem to parse?



Can you supply the version of the .NET SDK and Couchbase Server you’re using? Also, the query text may be useful.

Is there any chance there’s a proxy or firewall altering HTTP traffic on port 8093 between your client and the Query node?

I’m unaware of a way to see the bad response without running the SDK in debug mode, since the JSON body being received appears to be non-conformant.

Hi there,

The version of the SDK is, the version of Couchbase is Enterprise Edition 5.0.0 build 3519. The query I’m sending through is:

“SELECT * FROM Lunch WHERE cb_type = ‘PointOfInterest’ LIMIT 10 OFFSET 0”

Both the client and the query node are running on my dev machine and I’ve specifically allowed 8093 with the firewall so I don’t think its that.



Okay, I have a new theory. I wonder if it might have to do with your POCO not matching with the query result structure. Try changing the query to this:

SELECT Lunch.* FROM Lunch WHERE cb_type = ‘PointOfInterest’ LIMIT 10 OFFSET 0

Using * instead of Lunch.* nests the documents inside an attribute named Lunch. It’s designed to help make joins more powerful, but is a common point of confusion.


Unfortunately that didn’t work. Perhaps I’m doing something wrong with the type since I’m not actually using a POCO? I’m executing the query like so:

var result = bucket.QueryAsync<string>(query).Result;

Is that acceptable?



Okay yeah that was the problem, I changed the type to dynamic and the results are now returning correctly. Not exactly sure what the issue with having a string as the return type is, but I appreciate the help.

Thanks a lot!


That looks like the problem to me. Each result is currently going to be a JSON object, not a string, so it can’t deserialize.

If you’re trying to extract a specific string attribute, you should use SELECT RAW Lunch.attributeName to get the specific attribute into the string.

If you’re trying to get the whole document, you should either make a POCO that matches the structure, or use the dynamic keyword instead of string.