Default encoder for JSON
182151
def default(value):
    
    if isinstance(value, Decimal):
        primative = float(value)
        if int(primative) == primative:
            return int(primative)
        else:
            return primative
    elif isinstance(value, set):
        return list(value)
    elif isinstance(value, Binary):
        return b64encode(value.value)
    raise TypeError("Cannot encode %s value %r" % (type(value), value))
219076
def json_encode(obj):
    """"""
    try:
        return json_encode.encoder.encode(obj)
    except AttributeError:
        json_encode.encoder = DjangoJSONEncoder(default=six.text_type)
        return json_encode(obj)
1131456
function encode(data) {
  $.checkArgument(data instanceof Array, 'Must be Array');
  var base32 = '';
  for (var i=0; i<data.length; i++) {
    var value = data[i];
    $.checkArgument(0 <= value && value < 32, 'Non-base32, value ' + value);
    base32 += CHARSET[value];
  }
  return base32;
}
313437
protected final JSON defaultCreateJSON( Map model ) {
      if( skipBindingResult && jsonConfig.getJsonPropertyFilter() == null ){
         this.jsonConfig.setJsonPropertyFilter( new BindingResultPropertyFilter() );
      }
      return JSONSerializer.toJSON( model, jsonConfig );
   }
170824
function Encoder(options) {
  options = options || {};
  Transform.call(this, {objectMode: true});

  // string length chunk for bulk strings, strings large than this amount
  // are broken over process ticks so as not to block the event loop
  // note this is character length, not byte length
  this.strlen = options.strlen || 4096;

  // maximum array length before iterating using
  // setImmediate
  this.arrlen = 512;

  // allow buffers to be passed through untouched
  this.buffers = options.buffers;

  // treat buffers as bulk strings
  this.return_buffers = options.return_buffers;
}
1212784
function Encoder (opts) {
  if (!(this instanceof Encoder)) {
    return new Encoder(opts);
  }
  Transform.call(this, opts);

  // lame malloc()s the "gfp" buffer
  this.gfp = binding.lame_init();

  // set default options
  if (!opts) opts = {};
  if (null == opts.channels) opts.channels = 2;
  if (null == opts.bitDepth) opts.bitDepth = 16;
  if (null == opts.sampleRate) opts.sampleRate = 44100;
  if (null == opts.signed) opts.signed = opts.bitDepth != 8;

  if (opts.float && opts.bitDepth == DOUBLE_BITS) {
    this.inputType = PCM_TYPE_DOUBLE;
  } else if (opts.float && opts.bitDepth == FLOAT_BITS) {
    this.inputType = PCM_TYPE_FLOAT;
  } else if (!opts.float && opts.bitDepth == SHORT_BITS) {
    this.inputType = PCM_TYPE_SHORT_INT;
  } else {
    throw new Error('unsupported PCM format!');
  }

  // copy over opts to the encoder instance
  Object.keys(opts).forEach(function(key){
    if (key[0] != '_' && Encoder.prototype.hasOwnProperty(key)) {
      debug('setting opt %j', key);
      this[key] = opts[key];
    }
  }, this);
}
1216724
def default_encode(v):
    
    if isinstance(v, ObjectId):
        return unicode_type(v)

    if isinstance(v, datetime):
        return format_time(v)

    if isinstance(v, date):
        return format_time(v)

    return v
1112347
def get_lazystring_encoder(app):
    
    from speaklater import _LazyString

    class JSONEncoder(app.json_encoder):

        def default(self, o):
            if isinstance(o, _LazyString):
                return text_type(o)
            return super(JSONEncoder, self).default(o)

    return JSONEncoder
1065896
def encode(self, obj):
        """"""
        s = super(CustomEncoder, self).encode(obj)
        # If uncompressed, postprocess for formatting
        if len(s.splitlines()) > 1:
            s = self.postprocess(s)
        return s
1180180
def default(self, value):
        """"""
        if isinstance(value, ObjectId):
            return str(value)
        return super(ElasticJSONSerializer, self).default(value)
249364
def dumps(data, **kwargs):
    """"""

    def _encoder(value):
        if isinstance(value, datetime.datetime):
            return value.isoformat()

        if hasattr(value, "_data"):
            return value._data

        raise TypeError('Could not encode %r' % value)

    return json.dumps(data, default=_encoder, **kwargs)
1108323
def encode_params(params, **kwargs):
    """"""
    cleaned = clean_params(params, **kwargs)
    return json.dumps(cleaned)
565003
def dumps(obj):
    """"""
    return json.dumps(obj, indent=4, sort_keys=True, cls=CustomEncoder)
175573
def json_data(self, instance, default=None):
        
        value = self.get(instance)
        return api.to_iso_date(value) or default
957930
def _encode(cls, value):
        """"""

        value = json.dumps(value)
        return cls._ENC_RE.sub(lambda x: '%%%2x' % ord(x.group(0)), value)
820058
def string2json(self, string):
        """"""
        kwargs = {
            'cls': BytesEncoder,  # use the IPython bytes encoder
            'indent': 1,
            'sort_keys': True,
            'separators': (',', ': '),
        }
        return cast_unicode(json.dumps(string, **kwargs), 'utf-8')
947929
private byte[] encode(byte[] input) throws EncoderException
    {
        if (encoder != null)
        {
            return encoder.encode(input);
        }
        else
        {
            return DEFAULT_CODER.encode(input);
        }
    }