Skip to content

MessageToJson converts min_{property} from int to string #24131

@yangyw-g

Description

@yangyw-g

What language does this apply to?
This is concerning the python google.protobuf.json_format

Describe the problem you are trying to solve.
I am trying to convert proto message to json. For example

type: OBJECT
properties {
  key: "stories"
  value {
    type: ARRAY
    items {
      type: OBJECT
      properties {
        key: "category"
        value {
          type: STRING
          description: "News category"
        }
      }
      required: "category"
    }
    max_items: 10
    min_items: 10
  }
}
required: "stories"

json_format.MessageToJson(proto) outputs

{
  "type": "OBJECT",
  "properties": {
    "stories": {
      "type": "ARRAY",
      "items": {
        "type": "OBJECT",
        "properties": {
          "category": {
            "type": "STRING",
            "description": "News category"
          }
        },
        "required": [
          "category"
        ]
      },
      "maxItems": "10",
      "minItems": "10"
    }
  },
  "required": [
    "stories"
  ]
}

In the output maxItems and minItems are string "10", not integer. This causes trouble when validating the json using jsonschema.validate().

Describe the solution you'd like
The output of {min|max}_{property} should be integer, not string.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions