Don't sort keys when dumping json and yaml (#39214)
This commit is contained in:
parent
181709f3d2
commit
28332f23b3
3 changed files with 5 additions and 7 deletions
|
@ -47,9 +47,7 @@ class HomeAssistantView:
|
||||||
) -> web.Response:
|
) -> web.Response:
|
||||||
"""Return a JSON response."""
|
"""Return a JSON response."""
|
||||||
try:
|
try:
|
||||||
msg = json.dumps(
|
msg = json.dumps(result, cls=JSONEncoder, allow_nan=False).encode("UTF-8")
|
||||||
result, sort_keys=True, cls=JSONEncoder, allow_nan=False
|
|
||||||
).encode("UTF-8")
|
|
||||||
except (ValueError, TypeError) as err:
|
except (ValueError, TypeError) as err:
|
||||||
_LOGGER.error("Unable to serialize to JSON: %s\n%s", err, result)
|
_LOGGER.error("Unable to serialize to JSON: %s\n%s", err, result)
|
||||||
raise HTTPInternalServerError
|
raise HTTPInternalServerError
|
||||||
|
|
|
@ -54,7 +54,7 @@ def save_json(
|
||||||
Returns True on success.
|
Returns True on success.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
json_data = json.dumps(data, sort_keys=True, indent=4, cls=encoder)
|
json_data = json.dumps(data, indent=4, cls=encoder)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
msg = f"Failed to serialize to JSON: {filename}. Bad data at {format_unserializable_data(find_paths_unserializable_data(data))}"
|
msg = f"Failed to serialize to JSON: {filename}. Bad data at {format_unserializable_data(find_paths_unserializable_data(data))}"
|
||||||
_LOGGER.error(msg)
|
_LOGGER.error(msg)
|
||||||
|
|
|
@ -10,9 +10,9 @@ from .objects import NodeListClass
|
||||||
|
|
||||||
def dump(_dict: dict) -> str:
|
def dump(_dict: dict) -> str:
|
||||||
"""Dump YAML to a string and remove null."""
|
"""Dump YAML to a string and remove null."""
|
||||||
return yaml.safe_dump(_dict, default_flow_style=False, allow_unicode=True).replace(
|
return yaml.safe_dump(
|
||||||
": null\n", ":\n"
|
_dict, default_flow_style=False, allow_unicode=True, sort_keys=False
|
||||||
)
|
).replace(": null\n", ":\n")
|
||||||
|
|
||||||
|
|
||||||
def save_yaml(path: str, data: dict) -> None:
|
def save_yaml(path: str, data: dict) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue