JSON.parse: expected property name or '}' JavaScript

2

I have this String:

[
    {'lat':43.4627,'lng':-3.79636,'description':'a'}, 
    {'lat':43.4476,'lng':-3.82948,'description':'b'}, 
    {'lat':43.4228,'lng':-3.82391,'description':'c'}
]

And when I try to validate here I get this error:

SyntaxError: JSON.parse: expected property name or '}' at line 1 
column 2 of the JSON data

Can anyone tell me what's wrong with my String?

    
asked by Eduardo 10.05.2018 в 10:52
source

3 answers

2

The error you mention

  

JSON.parse: expected property name or '}'

or you can also get:

  

Expecting 'STRING', '}', got 'undefined'

Are provoked because double quotes are needed to define strings.

This would work correctly:

[{
        "lat": 43.4627,
        "lng": -3.79636,
        "description": "a"
    },
    {
        "lat": 43.4476,
        "lng": -3.82948,
        "description": "b"
    },
    {
        "lat": 43.4228,
        "lng": -3.82391,
        "description": "c"
    }
]

I recommend using a json validator in these cases.

    
answered by 10.05.2018 / 18:24
source
1

The names of the fields in the object should be doubled instead of single.

[
    {"lat":43.4627,"lng":-3.79636,"description":"a"}, 
    {"lat":43.4476,"lng":-3.82948,"description":"b"}, 
    {"lat":43.4228,"lng":-3.82391,"description":"c"}
]
    
answered by 10.05.2018 в 10:58
1

The names of the fields should be in double quotes instead of simple.

[
    {"lat":43.4627,"lng":-3.79636,"description":"a"}, 
    {"lat":43.4476,"lng":-3.82948,"description":"b"}, 
    {"lat":43.4228,"lng":-3.82391,"description":"c"}
]

According to the official documentation :

  

A value can be a string between double quotes , or a number, or   true or false or null, or an object or a matrix.

    
answered by 10.05.2018 в 10:59