Apoc.load.json for importing string

import
json

(Thomas Schmalz) #1

Does anybody know, if it is possible to import a json string directly via apoc.load.json instead of loading a file or an url with json data?

For example:

WITH '{
	"items": [{
		"question_id": 24620768,
		"link": "http://stackoverflow.com/questions/24620768/neo4j-cypher-query-get-last-n-elements",
		"title": "Neo4j cypher query: get last N elements",
		"answer_count": 1,
		"score": 1,
		"creation_date": 1404771217,
		"body_markdown": "I have a graph....How can I do that?",
		"tags": ["neo4j",
		"cypher"],
		"owner": {
			"reputation": 815,
			"user_id": 1212067,
			"link": "http://stackoverflow.com/users/1212067/"
		},
		"answers": [{
			"owner": {
				"reputation": 488,
				"user_id": 737080,
				"display_name": "Chris Leishman"
			},
			"answer_id": 24620959,
			"share_link": "http://stackoverflow.com/a/24620959",
			"body_markdown": "The simplest would be to use an ... some discussion on this here:...",
			"title": "Neo4j cypher query: get last N elements"
		}]
	}]
}' as jsonString 
CALL apoc.load.json(jsonString) YIELD value
UNWIND value.items as item
RETURN item.title, item.tags

Thanks in advance,

Regards, Thomas


(Michael Hunger) #2

You can use the function

...
WITH apoc.convert.fromJsonMap(jsonString) as value
UNWIND value.items as item
RETURN item.title, item.tags
╒═════════════════════════════════════════╤══════════════════╕
│"item.title"                             │"item.tags"       │
╞═════════════════════════════════════════╪══════════════════╡
│"Neo4j cypher query: get last N elements"│["neo4j","cypher"]│
└─────────────────────────────────────────┴──────────────────┘

(Thomas Schmalz) #3

Thank you Michael,

I hope to find the time to try this out within the next days and will give feedback if it did the job.

Regards, Thomas