]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/api/v1/format.py
fix new linting issues from pylint 2.16
[nominatim.git] / nominatim / api / v1 / format.py
index cb2b15a71725b33e5b3c5aac89f0232b89961281..116e2ae634e671a7ac191431e705dfd19d46da38 100644 (file)
@@ -7,12 +7,9 @@
 """
 Output formatters for API version v1.
 """
-from typing import Dict, Any
-from collections import OrderedDict
-import json
-
 from nominatim.api.result_formatting import FormatDispatcher
 from nominatim.api import StatusResult
+from nominatim.utils.json_writer import JsonWriter
 
 dispatch = FormatDispatcher()
 
@@ -26,13 +23,15 @@ def _format_status_text(result: StatusResult) -> str:
 
 @dispatch.format_func(StatusResult, 'json')
 def _format_status_json(result: StatusResult) -> str:
-    out: Dict[str, Any] = OrderedDict()
-    out['status'] = result.status
-    out['message'] = result.message
-    if result.data_updated is not None:
-        out['data_updated'] = result.data_updated.isoformat()
-    out['software_version'] = str(result.software_version)
-    if result.database_version is not None:
-        out['database_version'] = str(result.database_version)
+    out = JsonWriter()
+
+    out.start_object()\
+         .keyval('status', result.status)\
+         .keyval('message', result.message)\
+         .keyval_not_none('data_updated', result.data_updated,
+                          lambda v: v.isoformat())\
+         .keyval('software_version', str(result.software_version))\
+         .keyval_not_none('database_version', result.database_version, str)\
+       .end_object()
 
-    return json.dumps(out)
+    return out()