From 0199eb1045a0bcde4b12c128c08310177d2372dd Mon Sep 17 00:00:00 2001 From: prrao87 Date: Tue, 20 Aug 2024 10:57:21 -0400 Subject: [PATCH] Add JSON export docs --- src/content/docs/export/json.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/content/docs/export/json.md diff --git a/src/content/docs/export/json.md b/src/content/docs/export/json.md new file mode 100644 index 00000000..1b8b9a1e --- /dev/null +++ b/src/content/docs/export/json.md @@ -0,0 +1,32 @@ +--- +title: Export to JSON +--- + +The `COPY TO` clause can export query results to a JSON file. To use this feature, you have to install the +JSON extension using the instructions shown [here](/extensions/json). + +To demonstrate this, we will create a node table and insert some data into it. +```sql +CREATE NODE TABLE Person (id SERIAL, name STRING, info STRUCT(height DOUBLE, age INT64, previous_usernames STRING[]), PRIMARY KEY(id)); +``` +```cypher +CREATE (:Person {name: "Alice", info: {height: 1.68, age: 45, previous_usernames: ["alice123", "alice_34425"]}}); +CREATE (:Person {name: "Bob", info: {height: 1.81, age: 71, previous_usernames: ["the_builder", "the_minion"]}}); +CREATE (:Person {name: "Gregory", info: {height: 1.73, age: 22, previous_usernames: ["gregory7"]}}); +``` + +The following query will export the data from the `Person` node table to a JSON file. +```sql +COPY (MATCH (p:Person) RETURN p.*) TO 'people-output.json'; +``` +Result: + +```json +[ +{"p.id":0,"p.name":"Alice","p.info":{"height":1.68,"age":45,"previous_usernames":["alice123","alice_34425"]}}, +{"p.id":1,"p.name":"Bob","p.info":{"height":1.81,"age":71,"previous_usernames":["the_builder","the_minion"]}}, +{"p.id":2,"p.name":"Gregory","p.info":{"height":1.73,"age":22,"previous_usernames":["gregory7"]}} +] +``` + +You can use a JSON formatter to make the output more readable. \ No newline at end of file