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
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.
"""