def _copy_jsonsafe(value):
    """Deep-copy a value into JSON-safe types.
    """
    if isinstance(value, six.string_types + (numbers.Number,)):
        return value
    if isinstance(value, collections_abc.Mapping):
        return {six.text_type(k): _copy_jsonsafe(v) for k, v in value.items()}
    if isinstance(value, collections_abc.Iterable):
        return [_copy_jsonsafe(v) for v in value]
    if value is None:   # This doesn't happen often for us.
        return None
    return six.text_type(value)
Deep-copy a value into JSON-safe types.