code: public Serializer writeObject(JSONObject object) throws IOException {
          if (null == object) return writeNull();
  
          // write header
          writeRawString("{");
          indentPush();
  
          Iterator iter = null;
          if (object instanceof OrderedJSONObject)
          {
              iter = ((OrderedJSONObject)object).getOrder();
          }
          else
          {
              List propertyNames = getPropertyNames(object);
              iter = propertyNames.iterator();
          }
  
          while ( iter.hasNext() )
          {
              Object key = iter.next();
              if (!(key instanceof String)) throw new IOException("attempting to serialize object with an invalid property name: '" + key + "'" );
  
              Object value = object.get(key);
              if (!JSONObject.isValidObject(value)) throw new IOException("attempting to serialize object with an invalid property value: '" + value + "'");
  
              newLine();
              indent();
              writeString((String)key);
              writeRawString(":");
              space();
              write(value);
  
              if (iter.hasNext()) writeRawString(",");
          }
  
          // write trailer
          indentPop();
          newLine();
          indent();
          writeRawString("}");
  
          return this;
      }
docs: Method to write a complete JSON object to the stream.
  @param object The JSON object to write out.
  @throws IOException Thrown if an error occurs during write.