Read JSON file

    0

    95

    json
    Python public recipes

    Read JSON file and store it as a dictionary

    Shortcut: json.file.read

    import json
    
    if os.path.isfile(filename):
      with open(filename) as myfile:
        file_content = myfile.read()
        try:
          json_content = json.loads(file_content)
        except json.decoder.JSONDecodeError:
          # Cannot read the file
          json_content = None
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.