Kirill Simonov avatar 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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.