Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON invalid character '}' looking for beginning of object key string

I am attempting to import a .json file to parse.com, and I have encountered many errors while doing so. I solved them sequentially, but after I click finish import, I get the error

invalid character '}' looking for beginning of object key string

My JSON script is, as far as I know, perfectly fine. But I only started using JSON two hours ago, so I'm sure there's something wrong with it.

{
  "results": [{
    "nameChunk1": [{
      "name1": "Sean",
      "name2": "Noah",
    }]
    "nameChunk2": [{
      "name1": "Joseph",
      "name2": "Sam",
    }]
  }]
}

So, where is the mysterious invalid }? I fear there are many... Keep in mind I am using JSON for importing data into parse.com

like image 572
blaizor Avatar asked Apr 17 '15 05:04

blaizor


4 Answers

Correct your JSON syntax:

{
  "results": [{
     "nameChunk1": [{
        "name1": "Sean",
        "name2": "Noah" 
     }],
     "nameChunk2": [{
       "name1": "Joseph",
       "name2": "Sam"
     }]
  }]
}

Observe that I have added , after each array.. and removed , after name2 key.

Always use validators such as http://jsonlint.com/ to validate your JSON.

like image 185
Sandeep Nayak Avatar answered Oct 02 '22 09:10

Sandeep Nayak


Use any JSON validator like http://jsonlint.com/ to validate your JSON.

Correct JSON is:

{
  "results": [{
     "nameChunk1": [{
        "name1": "Sean",
        "name2": "Noah" 
     }],
     "nameChunk2": [{
       "name1": "Joseph",
       "name2": "Sam"
     }]
  }]
}
like image 23
Sachin Gupta Avatar answered Sep 28 '22 09:09

Sachin Gupta


You need to remove the comma's after name2 and then insert a comma between nameChunk1 and nameChunk2. Valid JSON below:

{
  "results": [{
    "nameChunk1": [{
      "name1": "Sean",
      "name2": "Noah"
    }],
    "nameChunk2": [{
      "name1": "Joseph",
      "name2": "Sam"
    }]
  }]
}
like image 3
Justin Ober Avatar answered Sep 30 '22 09:09

Justin Ober


There are two issues with the JSON:

  1. There should be no ',' after last element of an object
  2. There should be a comma to separate two elements

Below is the valid JSON:

{
  "results": [{
    "nameChunk1": [{
      "name1": "Sean",
      "name2": "Noah"
    }],
    "nameChunk2": [{
      "name1": "Joseph",
      "name2": "Sam"
    }]
  }]
}
like image 3
Mohsin Ali Avatar answered Sep 28 '22 09:09

Mohsin Ali