Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Parse error on line 1: in json data

I have following json in file mock.json. I am trying to load it via ajax call however, I am getting this error.

Error: Parse error on line 1:
{   id: 1,  name: 'My na
--^
Expecting 'STRING', '}', got 'undefined'

I used to jsonlint validator to validate json and getting above error. Whats wrong my json?

[{
    id: 1,
    name: 'My name',
    email: '[email protected]'
}]
like image 689
Om3ga Avatar asked Mar 10 '23 12:03

Om3ga


1 Answers

The JSON standard describes properties as strings and strings need double quotes ".

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

So you need double quotes for properties and values as strings in your JSON.

[{
    "id": 1,
    "name": "My name",
    "email": "[email protected]"
}]
like image 175
Nina Scholz Avatar answered Mar 13 '23 02:03

Nina Scholz