Fix bugs in JSONWriter