hedha hedha - 28 days ago 22
JSON Question

MongoDB import error : Failed: error reading separator after document #1: bad JSON array format - found no opening bracket '[' in input source

Here is my json file :

{"a":"b"}


When i am importing this file in database by this command:

mongoimport --db test --collection abc --jsonArray --file ABC.json


I got this error :

2016-11-10T15:03:39.696+0530 connected to: localhost
2016-11-10T15:03:39.697+0530 Failed: error reading separator after document #1: bad JSON array format - found no opening bracket '[' in input source
2016-11-10T15:03:39.697+0530 imported 0 documents


in my console.

There is no '[' symbol in my file. Can someone tell me where i am wrong?

Answer

Since you included the option --jsonArray, you must provide an array: [{"a":"b"}].

If you provide a single document, do not use the option --jsonArray.