code: public static String valueToString( Object value ) {
        if( value == null || isNull( value ) ){
           return "null";
        }
        if( value instanceof JSONFunction ){
           return ((JSONFunction) value).toString();
        }
        if( value instanceof JSONString ){
            return ((JSONString) value).toJSONString();
        }
        if( value instanceof Number ){
           return numberToString( (Number) value );
        }
        if( value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray ){
           return value.toString();
        }
        return quote( value.toString() );
     }
docs: Make a JSON text of an Object value. If the object has an
  value.toJSONString() method, then that method will be used to produce the
  JSON text. The method is required to produce a strictly conforming text.
  If the object does not contain a toJSONString method (which is the most
  common case), then a text will be produced by the rules.
  <p>
  Warning: This method assumes that the data structure is acyclical.
  
  @param value The value to be serialized.
  @return a printable, displayable, transmittable representation of the
  object, beginning with <code>{</code>&nbsp;<small>(left brace)</small>
  and ending with <code>}</code>&nbsp;<small>(right brace)</small>.
  @throws JSONException If the value is or contains an invalid number.