JSON serializer for objects not serializable by default json code
500322
def json_serial(obj):
    """"""
    if isinstance(obj, LegipyModel):
        return obj.to_json()
    elif isinstance(obj, (datetime.date, datetime.datetime)):
        return obj.isoformat()
    raise TypeError("Type {0} not serializable".format(repr(type(obj))))
388169
def _encode_json(obj):
    '''
    
    '''
    def _dump_obj(obj):
        if isinstance(obj, dict):
            return obj
        d = dict()
        for k in dir(obj):
            if not k.startswith('_'):
                d[k] = getattr(obj, k)
        return d
    return json.dumps(obj, default=_dump_obj)
642514
def _to_json_default(obj):
    
    # Datetime
    if isinstance(obj, datetime.datetime):
        return obj.isoformat()

    # UUID
    if isinstance(obj, uuid.UUID):
        return str(obj)

    # numpy
    if hasattr(obj, 'item'):
        return obj.item()

    # # Enum
    # if hasattr(obj, 'value'):
    #     return obj.value

    try:
        return obj.id
    except Exception:
        raise TypeError('{obj} is not JSON serializable'.format(obj=repr(obj)))
9772
def _json_convert(obj, json_options=DEFAULT_JSON_OPTIONS):
    
    if hasattr(obj, 'iteritems') or hasattr(obj, 'items'):  # PY3 support
        return SON(((k, _json_convert(v, json_options))
                    for k, v in iteritems(obj)))
    elif hasattr(obj, '__iter__') and not isinstance(obj, (text_type, bytes)):
        return list((_json_convert(v, json_options) for v in obj))
    try:
        return default(obj, json_options)
    except TypeError:
        return obj
1199546
def _get_serializer(cls, cls_for):
        

        if cls_for.__name__ in cls._custom_serializers:
            return cls._custom_serializers[cls_for.__name__]

        return JsonAdapter
20081
private ChannelBuffer serializeJSON(final Object obj) {
    if (query.hasQueryStringParam("jsonp")) {
      return ChannelBuffers.wrappedBuffer(
          JSON.serializeToJSONPBytes(query.getQueryStringParam("jsonp"), 
          obj));
    }
    return ChannelBuffers.wrappedBuffer(JSON.serializeToBytes(obj));
  }
340273
def _serialize_json(obj, fp):
    
    json.dump(obj, fp, indent=4, default=serialize)
792280
function serialize(object) {
	function replacer(key, value) {
		if (typeof value === 'string' && value.match(ISO8601_DATE_REGEX)) {
			value = new Date(value);
			value = value.toISOString();
		}
		return value;
	}

	return JSON.stringify(object, replacer);
}
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)
544400
def unserialize(jsonstr):
        '''
        
        '''
        topod = json.loads(jsonstr)
        G = json_graph.node_link_graph(topod)
        for n,ndict in G.nodes(data=True):
            if 'nodeobj' not in ndict or 'type' not in ndict:
                raise Exception("Required type information is not present in serialized node {} :{}".format(n, ndict))
            nobj = ndict['nodeobj']
            cls = eval(ndict['type'])
            ndict['nodeobj'] = cls(**dict(nobj))
        t = Topology(nxgraph=G)
        return t
860508
def default(self, obj):
        
        if isinstance(obj, datetime):
            return obj.isoformat()

        if issubclass(obj.__class__, Enum.__class__):
            return obj.value

        to_json = getattr(obj, 'to_json', None)
        if to_json:
            out = obj.to_json()
            if issubclass(obj.__class__, Model):
                out.update({'__type': obj.__class__.__name__})

            return out

        return JSONEncoder.default(self, obj)
271746
def serialize(obj):
    
    LOGGER.debug('serialize(%s)', obj)

    if isinstance(obj, datetime.date):
        return simplejson.dumps(obj, default=encoders.as_date)

    elif hasattr(obj, '__dict__'):
        return simplejson.dumps(obj, default=encoders.as_object)

    return simplejson.dumps(obj)
812109
def _encoder(self, obj):
        
        return {'__class__': obj.__class__.__name__,
                'ident': obj.ident,
                'group': obj.group,
                'name': obj.name,
                'ctype': obj.ctype,
                'pytype': obj.pytype,
                'access': obj.access}
        raise TypeError(repr(obj) + ' is not JSON serializable')
894105
def serialize(self, obj, method='json', beautify=False, raise_exception=False):
        """"""

        return self.helper.string.serialization.serialize(
            obj=obj, method=method, beautify=beautify, raise_exception=raise_exception)
1084416
def json_error(code, message):
    """"""
    # Message can be an unserializable object.
    message = repr(message)
    return jsonify(dict(request=request.path, message=message)), code
722212
def encode_json(self, serializable):
        
        return json.dumps(serializable.serialize(), cls=self.encoder)
924189
def toJson(self, data=None, pretty=False):
        """"""
        if data==None: data = self.attrs
        data = self.flatten(data) # don't send objects as str in json
        #if pretty:
        ret = json.dumps(data, indent=4, sort_keys=True)
        #self.inflate() # restore objects from json str data
        return ret