Write JSON to in a file

    0

    20

    Python public recipes

    The code opens the file "filename.json" in "w" mode, writes the JSON content to the file, and indents the code two spaces.

    Shortcut: json.write.tofile

    import json
    
    with open("filename", "w") as f:
      f.write(json.dumps("json_content", indent=2))
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.