There was an error manipulating the JSON object

Hi we are using Virtuoso in our portal, and when the system is trying the query so it can proccess the data, we get the followed error:

2020-05-21 15:01:37,730 [main] INFO  semantic.sync.SemanticSyncProcess - Trying query: http://datosgob-dev.digitalchannels.technology/virtuoso/sparql?query=select+distinct+%3FdatasetCount+where+%7B+graph+%3Chttp%3A%2F%2Fdatosgob-dev.digitalchannels.technology%2Fcatalogo%3E+%7B+%3Fx+%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Fterms%2Fextent%3E+%3FdatasetCount+%7D%7D&format=json
2020-05-21 15:01:37,764 [main] ERROR semantic.sync.SemanticSyncProcess - There was an error manipulating the JSON object.
org.json.JSONException: A JSONObject text must begin with '{' at 0 [character 1 line 1]
	at org.json.JSONTokener.syntaxError(JSONTokener.java:505)
	at org.json.JSONObject.<init>(JSONObject.java:214)
	at org.json.JSONObject.<init>(JSONObject.java:357)
	at semantic.sync.Utils.datasetsCountVirtuoso(Utils.java:180)
	at semantic.sync.SemanticSyncProcess.main(SemanticSyncProcess.java:221)
2020-05-21 15:01:37,765 [main] INFO  semantic.sync.SemanticSyncProcess - -1 datasets in Virtuoso
2020-05-21 15:01:37,765 [main] ERROR semantic.sync.SemanticSyncProcess - The number of datasets in Virtuoso is less than or equal to 0. Something went wrong.
2020-05-21 15:01:37,765 [main] INFO  semantic.sync.SemanticSyncProcess - End of process

The JSON that is giving as a response is:

{ "head": { "link": [], "vars": ["datasetCount"] },
  "results": { "distinct": false, "ordered": true, "bindings": [ ] } }

We’ve seen there’s a line break before the “{” making this the line 1 instead of line 0.

We have checked with another example and they have the same line break and everything works perfectly, so we don’t longer believe there’s a relation with the line break. However, we have kept checking all our config and we still don’t understand why this is not working.
Any help is welcome.
Thank you.

When I run the JSON response you indicate as being returned from Virtuoso ie

{ "head": { "link": [], "vars": ["datasetCount"] },
  "results": { "distinct": false, "ordered": true, "bindings": [ ] } }

like https://jsonlint.com/ , it is reported as being Valid JSON , so the problem seems to be in the application layer rather then Virtuoso …

What do you mean by “in the application layer”?
Because we have checked in our other environment and the JSON is giving more parameters in their JSON:

{ "head": { "link": [], "vars": ["datasetCount"] },
  "results": { "distinct": false, "ordered": true, "bindings": [
    { "datasetCount": { "type": "typed-literal", "datatype": "http://www.w3.org/2001/XMLSchema#nonNegativeInteger", "value": "27037" }} ] } }

Could be this “bindings” value make an effect on our Virtuoso making it not accept the JSON?

By application layer I mean whatever Java application is seeking to process the JSON result being by Virtuoso and generating the org.json.JSONException: A JSONObject text must begin with '{' at 0 [character 1 line 1] error, which I presume to this semantic.sync.SemanticSyncProcess application/module.

Where are you seeking to insert JSON data into Virtuoso that it might not be accepting, as from the query snippet originally post, I only see a SPARQL select ... query being executed ?