15

I tried to import a 7.4 MB JSON file via ...

mongoimport -d mongoimport -c test --file jsonTest.json

But I saw this issue.

Wed Sep 04 13:08:52.378 exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0

This Stackoverflow post presented a similar issue with respect to the date occurring before Jan 1, 1970, but that doesn't seem to apply given my FailedToParse: Expecting '{': offset:0 error.

Community
  • 1
  • 1
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
  • Have you sent it through a JSON validator? – Sammaye Sep 04 '13 at 17:17
  • I deleted text to reduce the 7.4 MB file down to 6 KB while maintaining the overall structure. Using JSON Viewer (Notepad++ plugin), I was able to parse the text as JSON. Then, I tried to run the above `mongoimport` on my 6 KB file, but got the same errors as I listed above. – Kevin Meredith Sep 04 '13 at 18:00
  • 2
    Can you post a sample of your json that is failing? – Ross Sep 05 '13 at 08:12
  • It can fail if there are linebreaks within tags – attish Sep 05 '13 at 08:50

2 Answers2

34

seems I'm much late but with the correct answer:

add --jsonArray in your statement and it will work. It should read like:

mongoimport -d mongoimport -c test --file jsonTest.json --jsonArray

Cheers!!

Sunny Sharma
  • 4,688
  • 5
  • 35
  • 73
  • 2
    Thanks, this helped solve my issue. My JSON file had multiple layers so adding the `--jsonArray` loaded it correctly. FYI on the mongo documentation, it means "load a json array, not one item per line. Currently limited to 16MB" – Will Sep 24 '14 at 13:55
2

Make sure that your json file is formatted correctly...Remove ' [ ' brackets at starting and ending if present. Check your json if you have any empty lines. Also check that the json documents have to separated by a new line..

harsha
  • 279
  • 2
  • 8
  • 1
    @harsha, removing the brackets will make it an object, not array. So it will will work in case you have only one object in that array and will Fail if you have more than one. – Sunny Sharma Feb 24 '14 at 06:03
  • Just for info : Use online json formatter to validate json http://www.jsoneditoronline.org/ – Ramesh Papaganti Jan 31 '17 at 12:58