title: Store multiple JSON documents (in row arrays format with nested JSON key-value objects) in MongoDB
body: <p>I have json file where each line looks like:</p>
  
  <pre><code>[1, "A", "B", 10, "{\"key\":\"val"}"]
  </code></pre>
  
  <p>How to import the file using JAVA driver api or other means?</p>
  
  <p>Using the below function :</p>
  
  <pre><code>public static void importJSONFileToDBUsingJavaDriver(String pathToFile, DB db, String collectionName) {
      // open file
      FileInputStream fstream = null;
      try {
          fstream = new FileInputStream(pathToFile);
      } catch (FileNotFoundException e) {
          e.printStackTrace();
          System.out.println("file not exist, exiting");
          return;
      }
      BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
  
      // read it line by line
      String strLine;
      DBCollection newColl =   db.getCollection(collectionName);
      try {
          while ((strLine = br.readLine()) != null) {
              // convert line by line to BSON
              DBObject bson = (DBObject) JSON.parse(JSONstr);
              // insert BSONs to database
              try {
                  newColl.insert(bson);
              }
              catch (MongoException e) {
                // duplicate key
                e.printStackTrace();
              }
  
  
          }
          br.close();
      } catch (IOException e) {
          e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
      }
  
  
  }
  </code></pre>
  
  <p>resulted in the following error (on line <code>newColl.insert(bson);</code>):</p>
  
  <pre><code>java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys, not: [_id]
  at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:161)
  at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:152)
  at org.bson.types.BasicBSONList.get(BasicBSONList.java:104)
  at com.mongodb.DBCollection.apply(DBCollection.java:766)
  at com.mongodb.DBCollection.apply(DBCollection.java:755)
  at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:242)
  at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:226)
  at com.mongodb.DBCollection.insert(DBCollection.java:75)
  at com.mongodb.DBCollection.insert(DBCollection.java:59)
  at com.mongodb.DBCollection.insert(DBCollection.java:104)
  </code></pre>
  
  <p>Trying to use mongoimport.exe utility :</p>
  
  <pre><code>mongoimport --db db --collection dbColl  &lt; rows.js
  </code></pre>
  
  <p>resulted in:</p>
  
  <pre><code>exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0
  </code></pre>
  
  <p>I would be happy if someone can refer me to JSON format specification which is acceptable by MongoDB. (i mean it can be converted to BSON, then DBObject can be built from it and this object can be inserted to MongoDB collection) </p>