So after receiving JSON with the following code:
ctype, pdict = cgi.parse_header(self.headers.get('content-type'))
if ctype == 'application/JSON':
length = int(self.headers.get('content-length'))
input = JSON.loads(self.rfile.read(length))
I received this kind of JSON from print(input) which is a dictionary:
{'packageInput': {'dog': [4.18, 0.08, 41.51, 0, 0, 0, 0, 0],
'cat': [2.752, 3.69, 2.29, 0, 0, 0, 0, 0],
'bird': [4.45, 4.97, 2.37, 0, 0, 0, 0, 0],
'chicken': [0.81, 0.61, '0.336', 0, 0, 0, 0, 0],
'min': ['1', 0, 0, 0, 0, 0, '5', 0, 0, 0, 0, 0],
'max': [4, 4, 4, 4, 100, 100, 100, 0, 0, 0, 0, 0]}}
As we can see, each "list" in the JSON has "array". How do I extract them into separate python list variable?
such as:
dog = []
cat = []
bird = []
chicken = []
I have been researching solutions, there are ranging from using for
loops to modules import. I believe there is a much more simple solution to extract this.
Would you please share an idea?