def serialize(value, output=None, use_fast_encoding=False, use_length_prefix_string=False):
    if output is None:
        # TODO:  Note, the problem here is that cStringIO.StringIO does not except unicode characters.  We need to
        # make a whole change to only use StringIO.StringIO, but it is not clear how that would impact performance.
        # We are going to defer for now.
        output = StringIO()
        # Remember that we have to return a string and not the output object.
        return_as_string = True
    else:
        return_as_string = False

    value_type = type(value)
    if value is None:
        output.write('null')
    elif value_type is str or value_type is unicode:
        if not use_length_prefix_string:
            output.write('"')
            output.write(__to_escaped_string(value, use_fast_encoding=use_fast_encoding))
            output.write('"')
        else:
            serialize_as_length_prefixed_string(value, output)
    elif value_type is dict or value_type is JsonObject:
        output.write('{')
        first = True
        for key in sorted(value.iterkeys()):
            if not first:
                output.write(',')
            output.write('"')
            output.write(__to_escaped_string(key, use_fast_encoding=use_fast_encoding))
            output.write('":')
            serialize(value[key], output, use_fast_encoding=use_fast_encoding)
            first = False
        output.write('}')
    elif value_type is list or value_type is JsonArray:
        output.write('[')
        first = True
        for element in value:
            if not first:
                output.write(',')
            serialize(element, output, use_fast_encoding=use_fast_encoding)
            first = False
        output.write(']')
    elif value_type is int or value_type is long:
        output.write(str(value))
    elif value_type is bool:
        if value:
            output.write('true')
        else:
            output.write('false')
    elif value_type is float:
        # TODO:  Handle Nan and Infinite
        output.write(str(value))
    else:
        raise JsonConversionException('Unknown value type when attempting to serialize as json: %s' %
                                      str(value_type))

    if return_as_string:
        return output.getvalue()
    else:
        return output

# Some regular expressions used for an optimized string escaping method
# based on code in the json lib in 2.7.
Fixture that returns cpu and gpu backends for 16 and 32 bit
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/json_lib/serializer.py/serialize--crossover with--dataset/ETHPy150Open NervanaSystems/neon/conftest.py/backend_tests