Skip to content

Commit 70cc07b

Browse files
committed
json.tool: --tab identation option
1 parent 3c67514 commit 70cc07b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Lib/json/tool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def main():
3333
'pretty-printing. Defaults to 4.')
3434
group.add_argument('--no-indent', action='store_const', dest='indent',
3535
const=None, help='Use compact mode.')
36+
group.add_argument('--tab', action='store_const', dest='indent',
37+
const='\t', help='Use tabs for indentation.')
3638
parser.add_argument('--sort-keys', action='store_true',
3739
help='sort the output of dictionaries by key')
3840
options = parser.parse_args()

Lib/test/test_json/test_tool.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,12 @@ def test_no_indent(self):
128128
json_stdout, err = proc.communicate(json_stdin)
129129
self.assertEqual(expect.splitlines(), json_stdout.splitlines())
130130
self.assertEqual(err, b'')
131+
132+
def test_tab(self):
133+
json_stdin = b'[1, 2]'
134+
expect = b'[\n\t1,\n\t2\n]\n'
135+
args = sys.executable, '-m', 'json.tool', '--tab'
136+
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
137+
json_stdout, err = proc.communicate(json_stdin)
138+
self.assertEqual(expect.splitlines(), json_stdout.splitlines())
139+
self.assertEqual(err, b'')

0 commit comments

Comments
 (0)