如何使用 Cypher Query 从 Neo4J 中的 json 文件中提取动态 属性 名称

How to extract dynamic property names from a json file in Neo4J using Cypher Query

标签 属性 名称是动态的。例如linux 和 cypher 在 json 中是动态的。我正在尝试提取动态标签及其值,并将它们作为属性关联到 Person 节点。这是我目前所拥有的:

CALL apoc.load.json("file:///example.json")
YIELD value
MERGE (p:Person {name: value.name})
ON CREATE SET 
p.job = value.job,
p.department = value.department

RETURN p as Person;

example.json:

{
    "name": "Harry",
    "job": "Developer",
    "tags": {
        "linux": "awesome",
        "cypher": "Working on it"
    },

    "department": "IT"

}

您可以使用 p += value.tags 语法从“tags”键分配所有属性,即:

CALL apoc.load.json("file:///example.json")
YIELD value
MERGE (p:Person {name: value.name})
ON CREATE SET 
    p.job = value.job,
    p.department = value.department,
    p += value.tags
RETURN p as Person

它创建以下节点(以您的数据为例):

{
  "identity": 29,
  "labels": [
    "Person"
  ],
  "properties": {
    "cypher": "Working on it",
    "linux": "awesome",
    "name": "Harry",
    "job": "Developer",
    "department": "IT"
  }
}

在此处查看文档:https://neo4j.com/docs/cypher-manual/current/clauses/set/#set-setting-properties-using-map