Fix serialization of 'datetime' objects in '--write-metadata'

Simplified universal serialization support in json.dump() can be achieved
by passing 'default=str', which was already the case in DataJob.run()
for -j/--dump-json, but not for the 'metadata' post-processor.

This commit introduces util.dump_json() that (more or less) unifies the
JSON output procedure of both --write-metadata and --dump-json.

(#251, #252)
This commit is contained in:
Mike Fährmann
2019-05-09 16:22:06 +02:00
parent 8de5866fd2
commit 523ebc9b0b
3 changed files with 16 additions and 14 deletions

View File

@@ -10,7 +10,6 @@
from .common import PostProcessor
from .. import util
import json
class MetadataPP(PostProcessor):
@@ -61,13 +60,7 @@ class MetadataPP(PostProcessor):
file.write("\n")
def _write_json(self, file, pathfmt):
json.dump(
pathfmt.keywords,
file,
sort_keys=True,
indent=self.indent,
ensure_ascii=self.ascii,
)
util.dump_json(pathfmt.keywords, file, self.ascii, self.indent)
__postprocessor__ = MetadataPP