0

I have a string representation of a js array

[{leervorm:"K", id:"48941AA9EE5AB0A1C1258526005CC082", lpzr:"", stap:1, hybride:true, training:[{locatie: "Eindhoven", periode:"07-07-2022, 08-07-2022, 14-07-2022 en 15-07-2022", prijs: 2095, id: "CAFA0A05F5576E3BC125875E004B739A", key: "AZ-104-220707-E"}]}, 

{leervorm:"B", id:"AAA64F74CB6F76CEC125853D00343484", lpzr:"", stap:2, hybride:true, training:[{locatie: "Eindhoven", periode:"08-06-2022, 15-06-2022 en 22-06-2022", prijs: 1695, id: "60826A0CC72D9F4FC125875E00352909", gaatdoor: 2, key: "BT-AZ-104-220608-E"}]

which I want to convert to a python list of dictionaries. Some answers on stackoverflow suggest using json, simplejson, ast.literal_eval but they fail because the keys are not wrapped in double quotes. My question is , do I have to write regular expressions to wrap every key in quotes or are there other options? Thank you in advance.

Sev
  • 77
  • 1
  • 7
  • Why not fix your source to give you proper JSON? Why do you have this format which is officially supported in JS source code? – VLAZ Jun 03 '22 at 18:05
  • I am scraping a website. The source is not under my control obviously) – Sev Jun 03 '22 at 18:10
  • did you get it from api request ? or something can you provide source i think if you scraping it it would be correct format for json but wrong while save – Thotsaphon Sirikutta Jun 03 '22 at 18:45
  • No its right in the html script tag. The full thing looks like this ` – Sev Jun 03 '22 at 18:56

0 Answers0