0

I have a list of dicts like that:

[{"group":'THIS',"score":0.99844724,"word":"this"},{"group":'THAT',"score":0.99844725,"word":"that"}]

And I am having trouble while using json.dump:

with open("inf_entities.json", "w") as inf_entities:
        json.dump(inf_task, inf_entities)
        inf_entities.close()

The problem I am facing is whenever json.dump is being used to write my list of dicts to that json file on top, it stops on the "score" key and it is unable to write down its value, saying : TypeError: Object of type float32 is not JSON serializable. I tried doing it like that:

 with open("inf_entities.json", "w") as inf_entities:
        json.dump(str(inf_task), inf_entities)
        inf_entities.close()

but I noticed that what was saved was a JSON string that I could not parse using json.load(). It was saved like that: "[{"group":'THIS',"score":0.99844724,"word":"this"},{"group":'THAT',"score":0.99844725,"word":"that"}]"

What I want to be saved inside my inf_entities.json is the entire list of dicts as a JSON that is neatly formatted and easy to access/parse.

I tried so many stackoveflow posts but with zero luck. Let me know if you need any more information regarding my problem or if it's not clear enough.

Zoi
  • 7
  • 3

0 Answers0