David542
David542

Reputation: 110382

Javascript JSON formatting equivalent in Python

I need to format something in this exact JSON format:

JSON.stringify(data,null,'\t');

How would I do this in python?

Upvotes: 1

Views: 2970

Answers (1)

Blender
Blender

Reputation: 298392

For Python 3:

import json

json.dumps(data, indent='\t')

If you're using Python 2 or need to support both versions, use the simplejson module:

import simplejson as json

The builtin json module in Python 2 indents only with spaces.

Upvotes: 1

Related Questions