Classes | Functions | Variables
google.protobuf.json_format Namespace Reference

Classes

class  _Parser
 
class  _Printer
 
class  Error
 
class  ParseError
 
class  SerializeToJsonError
 

Functions

def _ConvertBool (value, require_str)
 
def _ConvertFloat (value)
 
def _ConvertFloat (value, field)
 
def _ConvertInteger (value)
 
def _ConvertScalarFieldValue (value, field, require_str=False)
 
def _CreateMessageFromTypeUrl (type_url, descriptor_pool)
 
def _DuplicateChecker (js)
 
def _IsMapEntry (field)
 
def _IsWrapperMessage (message_descriptor)
 
def MessageToDict (message, including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, descriptor_pool=None)
 
def MessageToDict (message, including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, descriptor_pool=None, float_precision=None)
 
def MessageToJson (message, including_default_value_fields=False, preserving_proto_field_name=False, indent=2, sort_keys=False, use_integers_for_enums=False, descriptor_pool=None)
 
def MessageToJson (message, including_default_value_fields=False, preserving_proto_field_name=False, indent=2, sort_keys=False, use_integers_for_enums=False, descriptor_pool=None, float_precision=None)
 
def Parse (text, message, ignore_unknown_fields=False, descriptor_pool=None)
 
def ParseDict (js_dict, message, ignore_unknown_fields=False, descriptor_pool=None)
 

Variables

string __author__ = 'jieluo@google.com (Jie Luo)'
 
 _FLOAT_TYPES
 
string _INFINITY = 'Infinity'
 
 _INT64_TYPES
 
 _INT_OR_FLOAT = six.integer_types + (float,)
 
 _INT_TYPES
 
string _NAN = 'NaN'
 
string _NEG_INFINITY = '-Infinity'
 
string _TIMESTAMPFOMAT = '%Y-%m-%dT%H:%M:%S'
 
 _UNPAIRED_SURROGATE_PATTERN
 
 _VALID_EXTENSION_NAME = re.compile(r'\[[a-zA-Z0-9\._]*\]$')
 
dictionary _WKTJSONMETHODS
 

Function Documentation

◆ _ConvertBool()

def google.protobuf.json_format._ConvertBool (   value,
  require_str 
)
private
Convert a boolean value.

Args:
  value: A scalar value to convert.
  require_str: If True, value must be a str.

Returns:
  The bool parsed.

Raises:
  ParseError: If a boolean value couldn't be consumed.

Definition at line 775 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ _ConvertFloat() [1/2]

def google.protobuf.json_format._ConvertFloat (   value)
private
Convert an floating point number.

Definition at line 756 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ _ConvertFloat() [2/2]

def google.protobuf.json_format._ConvertFloat (   value,
  field 
)
private
Convert an floating point number.

Definition at line 780 of file protobuf/python/google/protobuf/json_format.py.

◆ _ConvertInteger()

def google.protobuf.json_format._ConvertInteger (   value)
private
Convert an integer.

Args:
  value: A scalar value to convert.

Returns:
  The integer value.

Raises:
  ParseError: If an integer couldn't be consumed.

Definition at line 735 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ _ConvertScalarFieldValue()

def google.protobuf.json_format._ConvertScalarFieldValue (   value,
  field,
  require_str = False 
)
private
Convert a single scalar field value.

Args:
  value: A scalar value to convert the scalar field value.
  field: The descriptor of the field to convert.
  require_str: If True, the field value must be a str.

Returns:
  The converted scalar field value

Raises:
  ParseError: In case of convert problems.

Definition at line 687 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ _CreateMessageFromTypeUrl()

def google.protobuf.json_format._CreateMessageFromTypeUrl (   type_url,
  descriptor_pool 
)
private
Creates a message from a type URL.

Definition at line 380 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ _DuplicateChecker()

def google.protobuf.json_format._DuplicateChecker (   js)
private

◆ _IsMapEntry()

def google.protobuf.json_format._IsMapEntry (   field)
private

◆ _IsWrapperMessage()

def google.protobuf.json_format._IsWrapperMessage (   message_descriptor)
private

◆ MessageToDict() [1/2]

def google.protobuf.json_format.MessageToDict (   message,
  including_default_value_fields = False,
  preserving_proto_field_name = False,
  use_integers_for_enums = False,
  descriptor_pool = None 
)
Converts protobuf message to a dictionary.

When the dictionary is encoded to JSON, it conforms to proto3 JSON spec.

Args:
  message: The protocol buffers message instance to serialize.
  including_default_value_fields: If True, singular primitive fields,
      repeated fields, and map fields will always be serialized.  If
      False, only serialize non-empty fields.  Singular message fields
      and oneof fields are not affected by this option.
  preserving_proto_field_name: If True, use the original proto field
      names as defined in the .proto file. If False, convert the field
      names to lowerCamelCase.
  use_integers_for_enums: If true, print integers instead of enum names.
  descriptor_pool: A Descriptor Pool for resolving types. If None use the
      default.

Returns:
  A dict representation of the protocol buffer message.

Definition at line 136 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ MessageToDict() [2/2]

def google.protobuf.json_format.MessageToDict (   message,
  including_default_value_fields = False,
  preserving_proto_field_name = False,
  use_integers_for_enums = False,
  descriptor_pool = None,
  float_precision = None 
)
Converts protobuf message to a dictionary.

When the dictionary is encoded to JSON, it conforms to proto3 JSON spec.

Args:
  message: The protocol buffers message instance to serialize.
  including_default_value_fields: If True, singular primitive fields,
      repeated fields, and map fields will always be serialized.  If
      False, only serialize non-empty fields.  Singular message fields
      and oneof fields are not affected by this option.
  preserving_proto_field_name: If True, use the original proto field
      names as defined in the .proto file. If False, convert the field
      names to lowerCamelCase.
  use_integers_for_enums: If true, print integers instead of enum names.
  descriptor_pool: A Descriptor Pool for resolving types. If None use the
      default.
  float_precision: If set, use this to specify float field valid digits.

Returns:
  A dict representation of the protocol buffer message.

Definition at line 130 of file protobuf/python/google/protobuf/json_format.py.

◆ MessageToJson() [1/2]

def google.protobuf.json_format.MessageToJson (   message,
  including_default_value_fields = False,
  preserving_proto_field_name = False,
  indent = 2,
  sort_keys = False,
  use_integers_for_enums = False,
  descriptor_pool = None 
)
Converts protobuf message to JSON format.

Args:
  message: The protocol buffers message instance to serialize.
  including_default_value_fields: If True, singular primitive fields,
      repeated fields, and map fields will always be serialized.  If
      False, only serialize non-empty fields.  Singular message fields
      and oneof fields are not affected by this option.
  preserving_proto_field_name: If True, use the original proto field
      names as defined in the .proto file. If False, convert the field
      names to lowerCamelCase.
  indent: The JSON object will be pretty-printed with this indent level.
      An indent level of 0 or negative will only insert newlines.
  sort_keys: If True, then the output will be sorted by field names.
  use_integers_for_enums: If true, print integers instead of enum names.
  descriptor_pool: A Descriptor Pool for resolving types. If None use the
      default.

Returns:
  A string containing the JSON formatted protocol buffer message.

Definition at line 99 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ MessageToJson() [2/2]

def google.protobuf.json_format.MessageToJson (   message,
  including_default_value_fields = False,
  preserving_proto_field_name = False,
  indent = 2,
  sort_keys = False,
  use_integers_for_enums = False,
  descriptor_pool = None,
  float_precision = None 
)
Converts protobuf message to JSON format.

Args:
  message: The protocol buffers message instance to serialize.
  including_default_value_fields: If True, singular primitive fields,
      repeated fields, and map fields will always be serialized.  If
      False, only serialize non-empty fields.  Singular message fields
      and oneof fields are not affected by this option.
  preserving_proto_field_name: If True, use the original proto field
      names as defined in the .proto file. If False, convert the field
      names to lowerCamelCase.
  indent: The JSON object will be pretty-printed with this indent level.
      An indent level of 0 or negative will only insert newlines.
  sort_keys: If True, then the output will be sorted by field names.
  use_integers_for_enums: If true, print integers instead of enum names.
  descriptor_pool: A Descriptor Pool for resolving types. If None use the
      default.
  float_precision: If set, use this to specify float field valid digits.

Returns:
  A string containing the JSON formatted protocol buffer message.

Definition at line 90 of file protobuf/python/google/protobuf/json_format.py.

◆ Parse()

def google.protobuf.json_format.Parse (   text,
  message,
  ignore_unknown_fields = False,
  descriptor_pool = None 
)
Parses a JSON representation of a protocol message into a message.

Args:
  text: Message JSON representation.
  message: A protocol buffer message to merge into.
  ignore_unknown_fields: If True, do not raise errors for unknown fields.
  descriptor_pool: A Descriptor Pool for resolving types. If None use the
      default.

Returns:
  The same message passed as argument.

Raises::
  ParseError: On JSON parsing problems.

Definition at line 394 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ ParseDict()

def google.protobuf.json_format.ParseDict (   js_dict,
  message,
  ignore_unknown_fields = False,
  descriptor_pool = None 
)
Parses a JSON dictionary representation into a message.

Args:
  js_dict: Dict representation of a JSON message.
  message: A protocol buffer message to merge into.
  ignore_unknown_fields: If True, do not raise errors for unknown fields.
  descriptor_pool: A Descriptor Pool for resolving types. If None use the
    default.

Returns:
  The same message passed as argument.

Definition at line 418 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

Variable Documentation

◆ __author__

string google.protobuf.json_format.__author__ = 'jieluo@google.com (Jie Luo)'
private

◆ _FLOAT_TYPES

google.protobuf.json_format._FLOAT_TYPES
private
Initial value:
1 = frozenset([descriptor.FieldDescriptor.CPPTYPE_FLOAT,
2  descriptor.FieldDescriptor.CPPTYPE_DOUBLE])

Definition at line 74 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ _INFINITY

string google.protobuf.json_format._INFINITY = 'Infinity'
private

◆ _INT64_TYPES

google.protobuf.json_format._INT64_TYPES
private
Initial value:
1 = frozenset([descriptor.FieldDescriptor.CPPTYPE_INT64,
2  descriptor.FieldDescriptor.CPPTYPE_UINT64])

Definition at line 72 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ _INT_OR_FLOAT

tuple google.protobuf.json_format._INT_OR_FLOAT = six.integer_types + (float,)
private

◆ _INT_TYPES

google.protobuf.json_format._INT_TYPES
private
Initial value:
1 = frozenset([descriptor.FieldDescriptor.CPPTYPE_INT32,
2  descriptor.FieldDescriptor.CPPTYPE_UINT32,
3  descriptor.FieldDescriptor.CPPTYPE_INT64,
4  descriptor.FieldDescriptor.CPPTYPE_UINT64])

Definition at line 68 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ _NAN

string google.protobuf.json_format._NAN = 'NaN'
private

◆ _NEG_INFINITY

string google.protobuf.json_format._NEG_INFINITY = '-Infinity'
private

◆ _TIMESTAMPFOMAT

string google.protobuf.json_format._TIMESTAMPFOMAT = '%Y-%m-%dT%H:%M:%S'
private

◆ _UNPAIRED_SURROGATE_PATTERN

google.protobuf.json_format._UNPAIRED_SURROGATE_PATTERN
private
Initial value:
1 = re.compile(six.u(
2  r'[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]'
3 ))

Definition at line 80 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.

◆ _VALID_EXTENSION_NAME

google.protobuf.json_format._VALID_EXTENSION_NAME = re.compile(r'\[[a-zA-Z0-9\._]*\]$')
private

◆ _WKTJSONMETHODS

dictionary google.protobuf.json_format._WKTJSONMETHODS
private
Initial value:
1 = {
2  'google.protobuf.Any': ['_AnyMessageToJsonObject',
3  '_ConvertAnyMessage'],
4  'google.protobuf.Duration': ['_GenericMessageToJsonObject',
5  '_ConvertGenericMessage'],
6  'google.protobuf.FieldMask': ['_GenericMessageToJsonObject',
7  '_ConvertGenericMessage'],
8  'google.protobuf.ListValue': ['_ListValueMessageToJsonObject',
9  '_ConvertListValueMessage'],
10  'google.protobuf.Struct': ['_StructMessageToJsonObject',
11  '_ConvertStructMessage'],
12  'google.protobuf.Timestamp': ['_GenericMessageToJsonObject',
13  '_ConvertGenericMessage'],
14  'google.protobuf.Value': ['_ValueMessageToJsonObject',
15  '_ConvertValueMessage']
16 }

Definition at line 800 of file bloaty/third_party/protobuf/python/google/protobuf/json_format.py.



grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:28