Om3ga
Om3ga

Reputation: 32823

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]'
}]

Upvotes: 4

Views: 15237

Answers (1)

Nina Scholz
Nina Scholz

Reputation: 386520

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]"
}]

Upvotes: 7

Related Questions