Write JSON to in a file



    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
    • Playground
    • Snippets
    • Cookbooks
    • 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.