mongodbimport Failure - FailedToParse: Expecting '{': offset:0
Asked Answered
H

2

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.

Harriettharrietta answered 4/9, 2013 at 17:16 Comment(4)
Have you sent it through a JSON validator?Nerveless
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.Harriettharrietta
Can you post a sample of your json that is failing?Dagan
It can fail if there are linebreaks within tagsMoan
C
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!!

Contraption answered 8/1, 2014 at 8:38 Comment(1)
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"Psycho
C
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..

Capote answered 8/10, 2013 at 13:59 Comment(2)
@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.Contraption
Just for info : Use online json formatter to validate json jsoneditoronline.orgJiminez

© 2022 - 2024 — McMap. All rights reserved.