Skip to content

Python: json_format.ParseValue #12535

Open
@xxgreg

Description

@xxgreg

What language does this apply to?

Python

Describe the problem you are trying to solve.

I would like to read a python value into a google.protobuf.Value type.

There is a json_format.ParseDict() function, however this only works if the top-level value is a google.protobuf.Struct.

It is already possible to use the unexported methods of the package to solve the problem, as in the example below.

Example of using unexported _Parser type to solve the problem.

def parse_value(value, target_pb):
    parser = json_format._Parser(False, None, 100)
    parser._ConvertValueMessage(value, target_pb, '')
    return value

Also - apologies if there is already a way to do this. If that is the case - treat this as a doc bug ;)

Describe the solution you'd like

One solution is to add a top-level json_format.ParseValue() function analogous to json_format.ParseDict().

Cheers team!

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions