-2

I have a file contain key value pairs below form:

[
  {
    af_NA: "Afrikaans (Namibia)",
    af_ZA: "Afrikaans (South Africa)",
    af: "Afrikaans",
    ak_GH: "Akan (Ghana)",
    ak: "Akan",
    sq_AL: "Albanian (Albania)",
    sq: "Albanian",
    am_ET: "Amharic (Ethiopia)",
    ...
  }
]

but keys are not in quotes. I want put all keys in quotes using python code. Thanks

Ali Asadi
  • 5
  • 5
  • Does this answer your question? [How to parse somewhat wrong JSON with Python?](https://stackoverflow.com/questions/1931454/how-to-parse-somewhat-wrong-json-with-python) – SuperStormer Sep 02 '20 at 21:21

1 Answers1

3

this looks like valid yaml, so you could use PyYaml to parse the file, then dump it to json

with open('your_file') as fl:
    data = yaml.safe_load(fl)
print(json.dumps(data))
Cyril Jouve
  • 990
  • 5
  • 15