瀏覽代碼

only start parsing json after the first open brace

Nick Sweeting 2 年之前
父節點
當前提交
aaca74f6a8
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      archivebox/parsers/generic_json.py

+ 4 - 2
archivebox/parsers/generic_json.py

@@ -17,8 +17,10 @@ def parse_generic_json_export(json_file: IO[str], **_kwargs) -> Iterable[Link]:
     """Parse JSON-format bookmarks export files (produced by pinboard.in/export/, or wallabag)"""
 
     json_file.seek(0)
-    next(json_file)
-    links = json.load(json_file)
+
+    # sometimes the first line is a comment or filepath, so we get everything after the first {
+    json_file_json_str = '{' + json_file.read().split('{', 1)[-1]
+    links = json.loads(json_file_json_str)
     json_date = lambda s: datetime.strptime(s, '%Y-%m-%dT%H:%M:%S%z')
 
     for link in links: