cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

JSON Parse Exception Unexpected character

I am trying to connect neo4j with DesiteMd through javascrift. But in neo4j i am getting the following message ''WARN /db/data/cypher org.codehaus.jackson.JsonParseException: Unexpected character ('o' (code 111)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: java.io.StringReader@3eb74e5; line: 1, column: 3]' The javascrift which I am using is

function myFunction5() {
var x = desiteAPI.getSelected(); 


        console.log(x);


        document.getElementById("demo").innerHTML = String(x);

        var myJSON = JSON.stringify ("x");

        var MatchQuery = new XMLHttpRequest();
        MatchQuery.open('POST', 'http://localhost:7474/db/data/cypher ', true);
        MatchQuery.setRequestHeader("Content-type", "application/json;charset=utf-8");//"Basic " + btoa("neo4j:123")


        var y = {"query" : "MATCH(a:" + String(x) + "), (b:Tasks) MERGE(a)-[r:relation]-(b) Return a,b"};



        console.log(y)



        MatchQuery.addEventListener('load', function (event) {
            if (MatchQuery.status >= 200 && MatchQuery.status < 300) {
                console.log(MatchQuery.responseText);

            } else {
                console.warn("error");
                console.warn(MatchQuery.statusText, MatchQuery.responseText);
            }
        });
    }`

Could somebody guide me kindly? Thank you

1 REPLY 1

There are several things in this code you need to check and possibly fix.

  1. In your cypher endpoint, you have an extra space at the end of the HTTP endpoint URL which is incorrect
  2. JSON.stringify("x") probably doesn't do what you intend - that will just return the string "x" because you're passing it a literal and not a variable. I'm not even sure you're using myJSON
  3. When you construct your cypher query with this: "MATCH(a:" + String(x) + ") I'm not sure the right thing is happening there either, and I can't see the value of the variable X. So the root cause is probably that you're constructing an invalid JSON object in 'y'.

Make sure that 'y' is valid JSON first.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online