Custom rewriter for json

23 views Asked by At

I am receiving a json string of the form

{
  "people": [
    {
      "Freddie": {
        "surname": "Mercury",
        "city": "London"
      }
    },
    {
      "David": {
        "surname": "Bowie",
        "city": "Berlin"
      }
    }
  ]
}

with the ultimate goal of recovering them as Proto messages of the kind

message Person {
  optional string name = 1;
  optional string surname = 2;
  optional string city = 3;
}

message Msg {
  repeated Person people = 1;
}

What is the best practice - i.e. short of custom adhoc logic of manipulating the keys - to convert the above json string to a string sich as

{
  "people": [
    {
      "name": "Freddie",
      "surname": "Mercury",
      "city": "London"
    },
    {
      "name": "David",
      "surname": "Bowie",
      "city": "Berlin"
    }
  ]
}

so that the correspondence between the json and the Proto is one-to-one, and therefore out-of-the-box deserializers could be used?

0

There are 0 answers