Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-03-2020 12:38 AM
Hello there, I'm trying to import a JSON with some conditions. The JSON file is a little complex, let's see why I'm saying this.
This is the file content.
{
"categories": [
{
"name": "Index Crime",
"sub_categories": [
{
"code": "01A",
"description": "Homicide 1st & 2nd Degree"
}
]
},
{
"name": "Non-Index Crime",
"sub_categories": "none"
},
]
}
As you can see, there is a sub-category that's an object composed by two values, and the other sub-category has the value none.
I want to import the first one as a node with the value 01A, and the other one, I don't want to create any node.
Is this possible, or do you see any other solution?
Thank you.
02-03-2020 01:51 AM
Hi
Small issue with your JSON, so I removed one comma
{
"categories": [{
"name": "Index Crime",
"sub_categories": [{
"code": "01A",
"description": "Homicide 1st & 2nd Degree"
}]
},
{
"name": "Non-Index Crime",
"sub_categories": "none"
}
]
}
You can use apoc.map.clean to clean your data from null-place holders
http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/utilities/map-functions/
WITH '14289.json' as filename
CALL apoc.load.json(filename) YIELD value AS v
UNWIND v.categories as categories
WITH apoc.map.clean(categories,[], ['none']) as categories
UNWIND categories.sub_categories as subcategory
RETURN categories.name as category, subcategory.code
Table
Text
Code
╒═════════════╤══════════════════╕
│"category" │"subcategory.code"│
╞═════════════╪══════════════════╡
│"Index Crime"│"01A" │
└─────────────┴──────────────────┘
02-03-2020 02:47 AM
Thank you Paul for your help!!
All the sessions of the conference are now available online