I would like to read a request, sent via curl, as given below:
curl -X POST http://127.0.0.1:8080/eval/res -v path/request.json. With the json having the following format:
{
"imgX": [{
"key": "x",
"url": "http://127.0.0.1:8080/imgs/x.png"
}],
"imgY": [{
"key": "y",
"url": "http://127.0.0.1:8080/imgs/y.png"
}]
}
After service initialization, my code is:
def preprocess(self, data):
_json = {}
for row in data:
json_obj = row.get("data") or row.get("body")
self.parameter_dict = dict(json_obj)
image_url = ""
json_obj = dict(json_obj)
for img_inputs, msk_inputs in zip(json_obj['imgX'], json_obj['imgY']):
key = img_inputs['key']
However, that gives:
KeyError: 'img'
I debug and find that when reading json file, each row is a bytearray:
{'body': bytearray(b'')}.
How can I decode to get the .json format back?