1. Prometheus Research, LLC
  2. Prometheus
  3. htsql

Commits

Kirill Simonov  committed 1b1d542

json: allow not stripping NULL values.

  • Participants
  • Parent commits 9c3eed5
  • Branches default

Comments (0)

Files changed (2)

File src/htsql/core/fmt/format.py

View file
  • Ignore whitespace
 
 
 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):

File src/htsql/core/fmt/json.py

View file
  • Ignore whitespace
     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)