mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
Fixing up jsonify and adding unit tests
This commit is contained in:
parent
a9d25f455c
commit
7c049c3200
3 changed files with 60 additions and 6 deletions
|
@ -29,17 +29,13 @@ def jsonify(result, format=False):
|
|||
|
||||
if result is None:
|
||||
return "{}"
|
||||
result2 = result.copy()
|
||||
for key, value in result2.items():
|
||||
if type(value) is str:
|
||||
result2[key] = value.decode('utf-8', 'ignore')
|
||||
|
||||
indent = None
|
||||
if format:
|
||||
indent = 4
|
||||
|
||||
try:
|
||||
return json.dumps(result2, sort_keys=True, indent=indent, ensure_ascii=False)
|
||||
return json.dumps(result, sort_keys=True, indent=indent, ensure_ascii=False)
|
||||
except UnicodeDecodeError:
|
||||
return json.dumps(result2, sort_keys=True, indent=indent)
|
||||
return json.dumps(result, sort_keys=True, indent=indent)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue