On this page
  1. json.dump
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

json.dump

Up: json | Next: json.dumps
Rel: json.dumps, json.JSONDecodeError, json.JSONDecoder, json.JSONEncoder
Ref: docs.python.org — json.dump
Tags: #public #python3 #stdlib #json


Import

import json
from json import dump

Signature & Overview

json.dump(obj, fp, *, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False, **kw)

Serialize obj as a JSON formatted stream to fp (a .write()-supporting file-like object).

Usage

import io
import json

buf = io.StringIO()
json.dump({"name": "Ada", "active": True}, buf, indent=2, sort_keys=True)
assert '"active": true' in buf.getvalue()

Gotchas

REPL Inspect

from json import dump
help(dump)

Linked from

Related notes