0

I have the following output in a file and wants to convert it into a dictionary or other structure in python which be meaningful. Note that in side a field { it is possible to have more blocks of fields recursively.

At the first look, it looks like a nested dictionary, I am looking for a dict like this:

{"A":{"B":"value_B","C":"value_C"}, "D":{"E":{"F":"value_F","G":value_G","H":"value_H","I":"value_I"}}}

fields {
    name: "ََA"
    fields {
      name: "B"
      string_value: "value_B"
    }
    fields {
      name: "C"
      bytes_value: "value_C"
    }
  }
 fields {
    name: "D"
    fields {
      name: "E"
      fields {
        name: "F"
        string_value: "value_F"
      }
      fields {
        name: "G"
        uint32_value: "value_G"
      }
      fields {
        name: "H"
        uint32_value: "value_H"
      }      
      fields {
        name: "I"
        fields {
          name: "J"
          uint32_value: "value_J"
        }
      }
    }
  }

Thanks.
Amir
  • 25
  • 4
  • This is not a valid python `dict` literal (or Json literal), is that the exact content of the file? – Tadhg McDonald-Jensen May 05 '16 at 17:21
  • You'll have to parse it. What format is this in? I've never seen it data structured like that before. It's possible there is already a parsing library if it's a standardized format. – Brendan Abel May 05 '16 at 17:23
  • This format is generated by protoc from google protocol buffer – Amir May 05 '16 at 17:30
  • Using a direct Internet search on *Google Python convert protoc dictionary*, I found [this](https://github.com/benhodgson/protobuf-to-dict). From all the hits I got, it looks like there are several converters already available. How do these not satisfy your needs? – Prune May 05 '16 at 18:16

0 Answers0