在 python 中为 Openrefine 创建 json

Create json in python for Openrefine

我正在 python 中抓取资源,我想制作一个 json 文件,在 Openrefine 中使用它来清理数据。

这是我的代码:

import json
import codecs

A = xpath
B = xpath
C = xpath
D = xpath

with codecs.open('info2.json', 'a', 'utf-8-sig') as f:
    json.dump({'A': A, 'B': B, 'C': C, 'D': D}, f, sort_keys=True, indent=4, ensure_ascii=False)

一切正常,直到我将文件上传到 Openrefine 中:我无法单击正确的节点,只能单击特定的元素。这是一个例子:

我认为用 python 生成 json 时出错,我尝试放置两个 {{}} 但它给了我一个 "dict" 错误,所以我尝试将元素放入数组,但没有任何效果。

根据要求,这里是 json 的一部分:

p.s。我正在使用编解码器,因为有非拉丁字符

要使节点在 OpenRefine 导入中可选择,您需要将数组包含在节点中 - 例如

{
  "DISTRIBUTION": [
    "JHU",
    "123"
  ],
  "IMMAGINE": {
    "IMMAGINELIST": [
      "1",
      "2",
      "3"
    ]
  }
}