user1814044
user1814044

Reputation: 47

JSON not getting validated through JSONLint

Below JSON is not getting validated. I am not able to find the issue

vartablearray=[
    {
        name: “Apple”,
        code: “APPL”,
        value: “111”,
        bid: “112”,
        offer: “110”
    },
    {
        name: “Microsoft”,
        code: “MSFT”,
        value: “78”,
        bid: “70”,
        offer: “75”
    },
    {
        name: “Google”,
        code: “GOGL”,
        value: “101”,
        bid: “98”,
        offer: “102”
    },
    {
        name: “Nokia”,
        code: “NOK”,
        value: “10”,
        bid: “8”,
        offer: “9”
    },
    {
        name: “Samsung”,
        code: “SAMS”,
        value: “89”,
        bid: “86”,
        offer: “90”
    },
    {
        name: “IntelCorporation”,
        code: “INTC”,
        value: “111”,
        bid: “112”,
        offer: “110”
    }
]

Upvotes: 0

Views: 139

Answers (2)

Srinivas
Srinivas

Reputation: 1790

Try this var tablearray= jQuery.parseJSON('[ { "name": "Apple", "code": "APPL", "value": "111", "bid": "112", "offer": "110" }, { "name": "Microsoft", "code": "MSFT", "value": "78", "bid": "70", "offer": "75" }, { "name": "Google", "code": "GOGL", "value": "101", "bid": "98", "offer": "102" }, { "name": "Nokia", "code": "NOK", "value": "10", "bid": "8", "offer": "9" }, { "name": "Samsung", "code": "SAMS", "value": "89", "bid": "86", "offer": "90" }, { "name": "IntelCorporation", "code": "INTC", "value": "111", "bid": "112", "offer": "110" } ]');

Upvotes: 1

John Dvorak
John Dvorak

Reputation: 27277

JSON requires the keys to be double-quoted:

[{ "name": "Apple", ... }]

var tablearray=[ { name: “Apple” } ] will cause syntax error in Javascript as well, since javascript doesn't understand the "fancy" double quotes you're using, only "plain" double quotes in the ASCII set: var tablearray=[ { name: "Apple" } ] or var tablearray=[ { "name": "Apple" } ]

Upvotes: 3

Related Questions