forked from NextTuesday/py-pb-converters
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddressbook_example.py
More file actions
39 lines (35 loc) · 805 Bytes
/
addressbook_example.py
File metadata and controls
39 lines (35 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from addressbook_pb2 import AddressBook
import pbjson
adr_book_json = {
"person": [
{
"name": "Mohamed Lee",
"id": 1,
"phone": [
{
"number": "+1234567890",
"type": 0
},
{
"number": "+2345678901",
"type": 1
}
]
},
{
"name": "Ben Bun",
"id": 2,
"email": "b@bun.com",
"phone": [
{
"number": "+1234567890",
"type": 0
}
]
}
]
}
#Convert JSoN to Protobuf
adr_book = pbjson.dict2pb(AddressBook, adr_book_json)
#Convert Protobuf to JSoN
new_json = pbjson.pb2json(adr_book)