X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c7e8a82d687758fea374edd43f11d1533d942b7b..657aae5f1bfebb99df5b9e6aa00c5b89269e4910:/nominatim/utils/json_writer.py diff --git a/nominatim/utils/json_writer.py b/nominatim/utils/json_writer.py index e2e5b9e6..fcc355d5 100644 --- a/nominatim/utils/json_writer.py +++ b/nominatim/utils/json_writer.py @@ -76,8 +76,8 @@ class JsonWriter: def end_array(self) -> 'JsonWriter': """ Write the closing bracket of a JSON array. """ - assert self.pending in (',', '[', '') - if self.pending == '[': + assert self.pending in (',', '[', ']', ')', '') + if self.pending not in (',', ''): self.data.write(self.pending) self.pending = ']' return self @@ -101,6 +101,11 @@ class JsonWriter: return self.raw(json.dumps(value, ensure_ascii=False)) + def float(self, value: float, precision: int) -> 'JsonWriter': + """ Write out a float value with the given precision. + """ + return self.raw(f"{value:0.{precision}f}") + def next(self) -> 'JsonWriter': """ Write out a delimiter comma between JSON object or array elements. """