code: public JSONArray element( int index, String value, JsonConfig jsonConfig ) {
        if( index < 0 ){
           throw new JSONException( "JSONArray[" + index + "] not found." );
        }
        if( index < size() ){
           if( value == null ){
              this.elements.set( index, "" );
           }else if( JSONUtils.mayBeJSON( value ) ){
              try{
                 this.elements.set( index, JSONSerializer.toJSON( value, jsonConfig ) );
              }catch( JSONException jsone ){
                 this.elements.set( index, JSONUtils.stripQuotes( value ) );
              }
           }else{
              this.elements.set( index, JSONUtils.stripQuotes( value ) );
           }
        }else{
           while( index != size() ){
              element( JSONNull.getInstance() );
           }
           element( value, jsonConfig );
        }
        return this;
     }
docs: Put or replace a String value in the JSONArray. If the index is greater
  than the length of the JSONArray, then null elements will be added as
  necessary to pad it out.<br>
  The string may be a valid JSON formatted string, in tha case, it will be
  transformed to a JSONArray, JSONObject or JSONNull.
  
  @param index The subscript.
  @param value A String value.
  @return this.
  @throws JSONException If the index is negative or if the the value is an
  invalid number.