1

I need to format something in this exact JSON format:

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

How would I do this in python?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

"TypeError: can't multiply sequence by non-int of type 'str'"
@GabiPurcaru: You're using Python 2. import simplejson as json instead.
You can still indent, just not with \t tabs. indent=4 will use 4 spaces instead of a tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.