Why I get this error when I want to start the grahpql server? I have no error on line 7 I want to start this server on port 3000 with json-graphql-server servergql.json.
This is my data from servergql.json. But I have no error on line 7..why I get this error? Please help. Is a problem with node modules?
{
students: [
{
id: 1,
name: "Pop Ion"
},
{
id: 2,
name: "Pop Maria"
}
],
courses: [
{
id: 1,
title: "Web development",
teacher: {
id: 1,
name: "Popescu Ion",
office: 404
}
},
{
id: 2,
title: "Java",
teacher: {
id: 1,
name: "Ionescu Maria",
office: 403
}
},
{
id: 3,
title: "Databases",
teacher: {
id: 1,
name: "Marian Vasile",
office: 401
}
}
],
grades: [
{
course_id: 1,
student_id: 1,
grade: 7
},
{
course_id: 1,
student_id: 2,
grade: 5
},
{
course_id: 2,
student_id: 1,
grade: 5
},
{
course_id: 2,
student_id: 2,
grade: 5
},
{
course_id: 3,
student_id: 2,
grade: 10
}
]
}
CodePudding user response:
The JSON you've written is malformed - for a valid JSON file your object keys must be strings and must be contained within quotes ("").
The error you're seeing somewhat shows you what the problem is: unexpected token s in JSON at position 7
which is highlighting that students
is not expected in the object yet.
Valid JSON would be:
{
"students": [
{
"id": 1,
"name": "Pop Ion"
},
{
"id": 2,
"name": "Pop Maria"
}
],
"courses": [
{
"id": 1,
"title": "Web development",
"teacher": {
"id": 1,
"name": "Popescu Ion",
"office": 404
}
},
{
"id": 2,
"title": "Java",
"teacher": {
"id": 1,
"name": "Ionescu Maria",
"office": 403
}
},
{
"id": 3,
"title": "Databases",
"teacher": {
"id": 1,
"name": "Marian Vasile",
"office": 401
}
}
],
"grades": [
{
"course_id": 1,
"student_id": 1,
"grade": 7
},
{
"course_id": 1,
"student_id": 2,
"grade": 5
},
{
"course_id": 2,
"student_id": 1,
"grade": 5
},
{
"course_id": 2,
"student_id": 2,
"grade": 5
},
{
"course_id": 3,
"student_id": 2,
"grade": 10
}
]
}
There are lots of online and development environment tools that you can use to lint your JSON to highlight any issues before you run into them in production (i.e. https://codebeautify.org/jsonvalidator)