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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user