Skip to content

Python json_format does not treat Empty as a well-known type #24445

@kmoon-work

Description

@kmoon-work

What version of protobuf and what language are you using?
Version: main (initially encountered on 6.31.1)
Language: Python

What operating system (Linux, Windows, ...) and version?
Linux (Ubuntu 24.04.3)

What runtime / compiler are you using (e.g., python version or gcc version)
Python 3.10.19

What did you do?
Steps to reproduce the behavior:

  1. Created an Any message containing an Empty value
  2. Serialized the message to JSON using Go
  3. Deserialized the message from JSON using Python

What did you expect to see
The deserialized Any message containing an Empty value.

The Go serializer produced the following JSON:

{
  "@type": "type.googleapis.com/google.protobuf.Empty",
  "value": {}
}

This is the correct serialization, according to the spec: https://protobuf.dev/programming-guides/json/#field-representation

What did you see instead?
Parse error:

ParseError: Failed to parse (elided) field: Message type "google.protobuf.Empty" has no field named "value" at "(elided)".
    Available Fields(except extensions): "[]".

The Python deserializer expects the following JSON:

{
  "@type": "type.googleapis.com/google.protobuf.Empty"
}

The root cause appears to be that json_format.py does not include google.protobuf.Empty in its list of well-known types (_WKTJSONMETHODS), and it is also not a wrapper type.

Anything else we should know about your project / environment
n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    jsonpythonuntriagedauto added to all issues by default when created.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions