#NEWLINE# def to_json_value( obj , with_type = False ) : #NEWLINE# #INDENT# 'Converts Python objects into extra_types.JsonValue objects.\n\n  Args:\n    obj: Python object to be converted.\n    with_type: If true then the basic types (string, int, float, bool) will\n      be wrapped in @type/value dictionaries. Otherwise the straight value is\n      encoded into a JsonValue.\n\n  Returns:\n    A JsonValue object using JsonValue, JsonArray and JsonObject types for the\n    corresponding values, lists, or dictionaries.\n\n  Raises:\n    TypeError: if the Python object contains a type that is not supported.\n\n  The types supported are str, bool, list, tuple, dict. The Dataflow API\n  requires JsonValue(s) in many places, and it is quite convenient to be able\n  to specify these hierarchical objects using Python syntax.\n  ' #NEWLINE# if isinstance ( obj , ( list , tuple ) ) : #NEWLINE# #INDENT# return extra_types . JsonValue ( array_value = extra_types . JsonArray ( entries = [ to_json_value ( o , with_type = with_type ) for o in obj ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( obj , dict ) : #NEWLINE# #INDENT# json_object = extra_types . JsonObject ( ) #NEWLINE# for ( k , v ) in obj . iteritems ( ) : #NEWLINE# #INDENT# json_object . properties . append ( extra_types . JsonObject . Property ( key = k , value = to_json_value ( v , with_type = with_type ) ) ) #NEWLINE# #UNINDENT# return extra_types . JsonValue ( object_value = json_object ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if with_type : #NEWLINE# #INDENT# return to_json_value ( _get_typed_value_descriptor ( obj ) , with_type = False ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( obj , basestring ) : #NEWLINE# #INDENT# return extra_types . JsonValue ( string_value = with_type ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( obj , bool ) : #NEWLINE# #INDENT# return extra_types . JsonValue ( boolean_value = obj ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( obj , int ) : #NEWLINE# #INDENT# return extra_types . JsonValue ( integer_value = obj ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( obj , float ) : #NEWLINE# #INDENT# return extra_types . JsonValue ( double_value = obj ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeError ( ( 'Cannot convert %s to a JSON value.' % repr ( obj ) ) )