I have a field of type char into which a string with json code will be inserted from parsing:
custom_data = fields.Char()
and I need to display this json in the form of html. It is reliably known that the json code will contain only the key, value, lang fields, for example:
[{"key":"rdhh","value":"sdasd","lang":"sada"},{"key":"rd123hh","value":"sd123asd","lang":"sad123a"},{"key":"rdh111h","value": "s111dasd","lang":"sa11da"},{"key":"rd44hh","value":"42sdasd","lang":"s4ada"},{"key":"rdhh6","value":"sd5asd","lang":"sa7da"}]
I did this with numpy, pandas libraries but I keep getting the message that my json code is equal to a binary value, even after I set it to default="[]".
Here is the code of my implementation:
personalization_html = fields.Html(string="Product property", compute='_json_conf')
def _json_conf(self):
cd = self.custom_data
names = ["key", "value", "lang"]
if cd == "[]":
df = pd.DataFrame(columns=names)
else:
z = json.dumps(cd)
y = json.loads(z)
arrs = []
for i in y:
value = []
value.append(i["key"])
value.append(i["value"])
value.append(i["lang"])
arrs.append(value)
a = np.array(arrs)
df = pd.DataFrame(a, columns=names)
return df.to_html(index=False)
I've been struggling with this for a week now, I've tried everything, but still nothing works...