Commits

Kirill Simonov committed 1b1d542

json: allow not stripping NULL values.

Comments (0)

Files changed (2)

src/htsql/core/fmt/format.py

 
 
 class RawFormat(Format):
-    pass
+
+    def __init__(self, with_null=False):
+        self.with_null = with_null
 
 
 class JSONFormat(Format):
-    pass
+
+    def __init__(self, with_null=False):
+        self.with_null = with_null
 
 
 class CSVFormat(Format):

src/htsql/core/fmt/json.py

     adapt(RawFormat)
 
     def __call__(self):
-        return dump_json(purge_null_keys(self.emit()))
+        tokens = self.emit()
+        if not self.format.with_null:
+            tokens = purge_null_keys(tokens)
+        return dump_json(tokens)
 
     def emit(self):
         data_to_raw = to_raw(self.meta.domain)
     adapt(JSONFormat)
 
     def __call__(self):
-        return dump_json(purge_null_keys(self.emit()))
+        tokens = self.emit()
+        if not self.format.with_null:
+            tokens = purge_null_keys(tokens)
+        return dump_json(tokens)
 
     def emit(self):
         product_to_json = to_json(self.meta.domain)