From 6f480fd03dcaaee7de399c408879797565b42088 Mon Sep 17 00:00:00 2001 From: Vladimir Dobriakov Date: Wed, 22 Aug 2018 21:55:30 +0200 Subject: [PATCH] Fixes #23078 - eliminate trailing whitespace in to_nice_json (#42633) * Fix #23078 - eliminate trailing whitespace in to_nice_json * Add changelog fragment for #42633 --- changelogs/fragments/to-nice-json-separators.yaml | 2 ++ lib/ansible/plugins/filter/core.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/to-nice-json-separators.yaml diff --git a/changelogs/fragments/to-nice-json-separators.yaml b/changelogs/fragments/to-nice-json-separators.yaml new file mode 100644 index 00000000000..a864d065bd7 --- /dev/null +++ b/changelogs/fragments/to-nice-json-separators.yaml @@ -0,0 +1,2 @@ +minor_changes: +- to_nice_json - specify separators to json.dumps to normalize the output between python2 and python3 (https://github.com/ansible/ansible/pull/42633) diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index aa1e04a174d..b56c5d527b9 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -87,7 +87,7 @@ def to_json(a, *args, **kw): def to_nice_json(a, indent=4, *args, **kw): '''Make verbose, human readable JSON''' try: - return json.dumps(a, indent=indent, sort_keys=True, cls=AnsibleJSONEncoder, *args, **kw) + return json.dumps(a, indent=indent, sort_keys=True, separators=(',', ': '), cls=AnsibleJSONEncoder, *args, **kw) except Exception as e: # Fallback to the to_json filter display.warning(u'Unable to convert data using to_nice_json, falling back to to_json: %s' % to_text(e))