Can json.dumps create multiple lines

Joaquin Alzola Joaquin.Alzola at
Thu Dec 1 12:17:47 EST 2016

On Thu, Dec 1, 2016 at 10:30 AM, Cecil Westerhof <Cecil at> wrote:
> I would prefer when it would generate:
>     '[
>      "An array",
>      "with several strings",
>      "as a demo"
>      ]'
> Is this possible, or do I have to code this myself?


>>>> json.dumps(["An array", "with several strings", "as a demo"], indent=0)
>'[\n"An array",\n"with several strings",\n"as a demo"\n]'
>>>> print(_)
>"An array",
>"with several strings",
>"as a demo"

As Zac stated the indent:
>>> print(json.dumps(["An array",{"Dummy":{'wop':'dop','dap':'dap'}}, "with several strings", "as a demo"], sort_keys = True, indent=4))
    "An array",
        "Dummy": {
            "dap": "dap",
            "wop": "dop"
    "with several strings",
    "as a demo"
This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.

More information about the Python-list mailing list