Bohdan  Afanasyev Bohdan Afanasyev - 5 months ago 17
JSON Question

Parse Error in JSON Format

Please explain what is my Parser Error in this JSON object.

db.products.insert({
name: "Microsoft Surface",
category: 'Electronics',
model: '7G5-33333',
})


P.S: JSONLint says, but I can't figure out...

Error: Parse error on line 1:
db.products.insert({
^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

Answer

Remove the comma at the end (after the model value).

db.products.insert({
    name: "Microsoft Surface",
    category: 'Electronics',
    model: '7G5-33333'
})

Having the comma there indicates there are more key-value pairs, so that's why you're seeing the "missing } after property list" error.