title: Constructing a Mongo DBObject from single-quote JS object with escaped characters?
body: <p>This question relates to the Java API / Driver, but may also be relevant to interfacing Mongo in other languages.  I am new to Mongo and making some assumptions, so please correct me if I'm mistaken.  A lot of documentation I'm finding, and <a href="https://stackoverflow.com/a/16333737/320399">references</a> describe creating a DBObject given a structure like this: </p>
  
  <pre><code>{
      foo: "bar",
      baz: {
          x : { lorem: "Ipsum" },
          y: { dolor : "sit amet" }
      }
  }
  </code></pre>
  
  <p>Assume the above object exists (unchanged) in a file called <code>foo.json</code>.  Now, as I understand it, the content above is a JavaScript <em>object literal</em> (not valid JSON).  Right?  However, this is the form referenced as "JSON" in the Mongo documentation.</p>
  
  <p>In any case, in my tests, I'm reading the <code>foo.json</code> file into a String and parsing it using (I believe) a fairly standard convention: </p>
  
  <pre><code>String fooString = readFile("foo.json");
  Object o = com.mongodb.util.JSON.parse(fooString);
  DBObject dbObj = (DBObject) o;
  </code></pre>
  
  <p>This works just fine.  Now, since <code>foo.json</code> isn't valid JSON, I assumed I'd be able to use a similar JavaScript object form:</p>
  
  <pre><code>{
      foo: 'bar',
      baz: {
          x : { lorem: 'Ipsum' },
          y: { dolor : 'sit amet' }
      }
  }
  </code></pre>
  
  <p>Ok, fine, that seems to work.  Although, oddly enough in Mongo shell it appears to be stored with double quotes.  Since that works, I'm making another assumption that I'd be able to handle the JavaScript object form with escaped single quotes: </p>
  
  <pre><code>{
      foo: 'bar',
      baz: {
          x : { lorem: 'Ipsum.  Isn\'t working' },
          y: { dolor : 'sit amet' }
      }
  }
  </code></pre>
  
  <p>However, when I try to parse this object (using <code>com.mongodb.util.JSON.parse(fooString)</code> ), a <code>com.mongodb.util.JSONParseException</code> is thrown.  Shouldn't all 3 forms be supported?</p>
  
  <p>Note: I'm using the org.mongodb:mongo-java-driver:mongo-java-driver:2.11.2 .  </p>
  
  <p>Thanks in advance for any/all help.</p>