Can json.dumps create multiple lines

John Gordon gordon at
Thu Dec 1 11:57:17 EST 2016

In <87lgvz4no8.fsf at> Cecil Westerhof <Cecil at> writes:

> I started to use json.dumps to put things in a SQLite database. But I
> think it would be handy when it would be easy to change the values
> manually.

> When I have a value dummy which contains:
>     ['An array', 'with several strings', 'as a demo']
> Then json.dumps(dummy) would generate:
>     '["An array", "with several strings", "as a demo"]'
> I would prefer when it would generate:
>     '[
>      "An array",
>      "with several strings",
>      "as a demo"
>      ]'

json.dumps() has an 'indent' keyword argument, but I believe it only
enables indenting of each whole element, not individual members of a list.

Perhaps something in the pprint module?

John Gordon                   A is for Amy, who fell down the stairs
gordon at              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

More information about the Python-list mailing list