cancel
Showing results for 
Search instead for 
Did you mean: 

Import a JSON with objects with arrays

gorkasalauniver
Node Clone

Hello everybidy,
I´m trying to import a JSON file:

{
    "observables": {
        "constants": [
            {
                "name": "VAR_1",
                "value": "2"
            },
            {
                "name": "VAR_2",
                "value": "3000"
            }
        ],
        "inputs": [
            {
                "name": "VAR_3",
                "type": "int"
            }
        ],
        "outputs": [
            {
                "name": "VAR_4",
                "type": "bool"
            }
        ]
    },
    "requirements": [
        {
            "id": "R0",
            "requirement": "textexample1",
            "variables": [
                "VAR_1",
                "VAR_2",
                "VAR_3"
            ]
        },
        {
            "id": "R1",
            "requirement": "textexample2",
            "variables": [
                "VAR_2",
                "VAR_3",
                "VAR_4"
            ]
        }
    ]
}

This is an example about a which type of JSON I will import.

So what I'm trying to get is a Node called requirement with the identifier id and the text.
This Node is going to be related with different nodes called variables, as you can see in the JSON there is an array that contains the variables.
This variables will have a namea type and a class, the class is output, input or constant.
I have be able to import the requirement and relate them with the variables, but I couldn´t add the information to the variable nodes.

CALL apoc.load.json("example.json") YIELD value AS file
WITH *
UNWIND file.observables AS observables
UNWIND file.requirements AS requirements
MERGE (r:Requirement{id: requirements.id, text:requirements.requirement})
WITH *
UNWIND requirements.variables AS variables
MERGE (v:Variable{nombre: variables})
MERGE (r)-[:USE]->(v)

How could be possible to add the information to the variables?

Thank You

0 REPLIES 0
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.