Coerce 'value' to an JSON-compatible representation.
330454
def _bytes_to_json(value):
    """"""
    if isinstance(value, bytes):
        value = base64.standard_b64encode(value).decode("ascii")
    return value
1005156
def __type2js(cls, value):
        
        if value is None:
            return 'null'
        elif isinstance(value, bool):
            return 'false' if not value else 'true'
        elif isinstance(value, (int, float)):
            return '%s' % value
        elif isinstance(value, dict):
            return json.dumps(dict)
        return '"%s"' % value
775589
def fromJSON(value):
        
        j = json.loads(value)
        v = GPLong()
        if "defaultValue" in j:
            v.value = j['defaultValue']
        else:
            v.value = j['value']
        if 'paramName' in j:
            v.paramName = j['paramName']
        elif 'name' in j:
            v.paramName = j['name']
        return v
349838
def coerce(self, value):
        
        if isinstance(value, compat.basestring):

            return value

        return str(value)
1287211
def to_json(value, **kwargs):
        
        b64rep = base64.b64encode(value.read())
        value.seek(0)
        jsonrep = '{preamble}{b64}'.format(
            preamble=PNG_PREAMBLE,
            b64=b64rep.decode(),
        )
        return jsonrep
1112415
def coerce(self, value):
        """"""
        if isinstance(value, dict):
            value = [value]
        if not isiterable_notstring(value):
            value = [value]
        return [coerce_single_instance(self.lookup_field, v) for v in value]
422810
def str2type(value):
    
    if not isinstance(value, str):
        return value
    try:
        return json.loads(value)
    except JSONDecodeError:
        return value
351852
def is_json_compat(value):
    

    try:
        value = json.loads(value)
    except ValueError as e:
        raise ValueError('JSON decoding error: ' + str(e))
    except TypeError:
        # Check that the value can be serialized back into json.
        try:
            json.dumps(value)
        except TypeError as e:
            raise ValueError(
                'must be a JSON serializable object: ' + str(e))

    if not isinstance(value, dict):
        raise ValueError(
            'must be specified as a JSON serializable dict or a '
            'JSON deserializable string'
        )

    return True
1354140
def fromJSON(value):
        
        j = json.loads(value)
        v = GPRecordSet()
        if "defaultValue" in j:
            v.value = j['defaultValue']
        else:
            v.value = j['value']
        if 'paramName' in j:
            v.paramName = j['paramName']
        elif 'name' in j:
            v.paramName = j['name']
        return v
763560
function encode ( value, quotes ) {
	const shouldQuote = quotes.getValue();
	let resolvedValue = JSON.stringify(getJsonValueFromSassValue(value, { precision: this.options.precision }));
	if ( shouldQuote ) {
		resolvedValue = `'${resolvedValue}'`;
	}
	return new types.String(resolvedValue);
}
486066
def to_json(value, **kwargs):
        
        def _recurse_list(val):
            if val and isinstance(val[0], list):
                return [_recurse_list(v) for v in val]
            return [str(v) if np.isnan(v) or np.isinf(v) else v for v in val]
        return _recurse_list(value.tolist())
613075
def _decimal_to_json(value):
    """"""
    if isinstance(value, decimal.Decimal):
        value = str(value)
    return value
1232437
def to_json(value, **kwargs):
        
        serial_dict = {
            key: (
                val.serialize(**kwargs) if isinstance(val, HasProperties)
                else val
            )
            for key, val in iteritems(value)
        }
        return serial_dict
641093
def to_string(self, value):
        
        self.enforce_type(value)
        if isinstance(value, dict) and None in value:
            value = value.copy()
            value['null'] = value[None]
            del value[None]
        return super(Dict, self).to_string(value)
962944
def to_representation(self, value):
        
        return {
            six.text_type(key): self.child.to_representation(val)
            for key, val in value.items()
        }
219655
function coerceDate (value) {
  if (!(value instanceof Date)) {
    // Is this how you raise a 'field error'?
    throw new Error('Field error: value is not an instance of Date')
  }
  if (isNaN(value.getTime())) {
    throw new Error('Field error: value is an invalid Date')
  }
  return value.toJSON()
}
1212320
def coerce(self, value):
        """"""
        if self.type == Style:
            return value
        elif self.type == list:
            return self.type(
                map(self.subtype, map(lambda x: x.strip(), value.split(',')))
            )
        elif self.type == dict:
            rv = {}
            for pair in value.split(','):
                key, val = pair.split(':')
                key = key.strip()
                val = val.strip()
                try:
                    rv[key] = self.subtype(val)
                except Exception:
                    rv[key] = val
            return rv
        return self.type(value)