cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Apoc.load.json for importing string

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

2 REPLIES 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"]│
└─────────────────────────────────────────┴──────────────────┘

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