Creating a JSON representation of a complete graph from NEO4J using JavaScript

I am having trouble finding a complete working code example for apoc.export.json.data.

It seems like the MATCH query could be used to retrieve any graph:

MATCH g=(someNode)-[someRel]-() RETURN g
CALL apoc.export.json.data( g )

Hopefully, this APOC function would generate JSON containing all the nodes and edges in the dataset based on the query. The expected JSON format is:

{
  nodes:[
    { id:a1a1 , labels:[Something] , prop_a:99 },
    { id:a2a2 , labels:[Something] , prop_a:77 },
    { id:a3a3 , labels:[User] ,      prop_a:33 }
  ],
  edges:[
    { id:a1a1 , labels:[OWNS] , prop_a:99 },
    { id:a2a3 , labels:[OWNS] , prop_a:77 },
    { id:a4a5 , labels:[HAS] ,  prop_a:33 }
  ]
}

Answer №1

Instead of relying on APOC, consider creating custom output in the following manner;

MATCH   g = ()-[]-()  
RETURN {nodes: myCustom.flatten(myCustom.collectDistinctNodes(g)), 
        edges: myCustom.flatten(myCustom.collectDistinctRelationships(g)) } as result

I am using version 5.4 of Enterprise edition, so this approach should function properly.

Here is a sample outcome:

https://i.sstatic.net/tKZqy.jpg

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting minified JavaScript in live environment

Trying to wrap my head around AngularJS and Grunt. In my GruntFile.js, I have set up two grunt tasks for development and production. In production, I am using uglification to combine multiple js files into one. I am in need of some advice or tips on how t ...

What is the best way to retrieve a value from a JSON object in Laravel?

I am working with 3 tables Product(id, sku, product_name) product_sales_forecast_3(id,product_id) product_sales_forecast_detail_3(id,product_sales_forecast,forecast,year) The forecast field in the table product_sales_forecast_detail_3 is represented as ...

Utilizing C# custom classes for parsing JSON data

I've been struggling to deserialize a JSON response in my application. Despite following multiple tutorials and articles, I haven't been successful - the List always ends up empty after deserialization. Below is the test JSON data and my current ...

What is the best way to incorporate a PHP file into an HTML file?

Below is the code snippet from my index.php: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Voting Page</title> <script type="text/javascript" src="js/jquer ...

Unable to establish proper functionality of username variables in Node.js chat application

For my latest project, I am developing a chat application in node.js following a tutorial from socket.io. The main objective of the app is to allow users to input their username along with a message, which will then be displayed as "username: message" in t ...

Use JavaScript to transfer list values to a textbox area

<!doctype html> <html> <head> <meta charset="utf-8"/> <title>My Title</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <s ...

Utilizing Javascript to retrieve the current Controller and Action in Rails

Is it possible for JavaScript to determine the current controller and action in Rails? I had the idea of creating a hidden container to store the current controller and action, but I'm curious if there is a specific JavaScript function for this purpo ...

Using asp.net along with Ajax for dynamic web development

I need to update my JavaScript code in order to refresh a different page window.opener.location.replace(url) However, a problem arises when trying to specify the path to the root where the page is located. Currently, the calling code is placed in a page ...

Issue with Sheetjs: Date format is not recognized when adding JSON data to a

I am struggling to export JSON data to Excel while maintaining the correct date format of 2020-07-30 07:31:45. Despite trying suggestions from a helpful post on sheetjs, I still couldn't get it right. Here is an example of the JSON data: { "so ...

JavaScript: Discovering similar property values within complexly nested arrays and objects

I am facing an issue with matching values from two JSON sources. While using the javascript find method, I have found that it works when the nesting of the "cities" array is one level more shallow (just an array of objects), but doesn't work with deep ...

Is it possible to create a unique JsonConverter for each object?

I am faced with a Json object that looks something like this: {"company": "My Company", "companyStart" : "2015/01/01", "employee" : { "name" : "john doe", "startDate" : 1420434000000 } } In addition, my json object looks like this: public cla ...

Idea: Develop a bookmarklet that generates a header form and deletes it upon submission

After much contemplation and experimentation, I have been grappling with the idea of creating a bookmarklet that displays a header when clicked on any webpage. This header will contain a small form that submits its contents to a server before disappearing. ...

Decoding nested objects into a unified list using JSON.net

Working on deserializing a JSON response into C# objects using JSON.net. Struggling with converting nested objects into a C# list. Here is the JSON response I am dealing with: The goal is to gather all nodes under variants into a single List<Varia ...

Is the return type for EvaluateJavaScript restricted to only String values?

One of the challenges I faced was creating a common function in Kotlin that could invoke a JavaScript function based on the command provided. fun evaluateJsFromNative(command: String, webView: WebView, function: (value : String) -> Unit ) ...

What is the best way to implement a "number of users currently online" feature in a Meteor application?

Currently, I am developing a Meteor application and I am interested in implementing a feature that displays the number of users currently visiting the website, much like omegle.com which shows "38,000+ online now" or a similar message. I'm unsure if t ...

Power Punch - Interactive Click Functionality

My question pertains to the click binding in Knockout and a specific behavior that I have observed. While there are numerous questions about click bindings on this platform, none seem to address the behavior I am encountering. I have grasped that in Knock ...

Eslint error: Attempting to assign to rvalue in ES6 function definitions

Currently, I have eslint configured like this: { "extends": "google", "installedESLint": true } When running lint on the following function: app.get('/', (req, res) => { console.log(req); res.send('hello world') }); I ...

The Sinon stub appears to be completely ignored during the test, despite its successful use in earlier tests

I am currently testing the functionality of an express router using sinon. The first test in my code below passes without any issues, but I'm having trouble with the second test. It's not passing and I can't seem to figure out why. When I s ...

Issue encountered while attempting to send CURL requests to ElasticSearch server

Need help with indexing strings on an ElasticSearch server running on a DigitalOcean droplet. The code compiles fine but the Curl requests yield different outputs - 'Authorization required' and Apache2 Default Page content. Is this a network issu ...

Tips for transferring information from a controller to a directive using the $emit method

I am facing an issue passing values from the controller to the directive Within my controller, I have two arrays defined as: $scope.displayPeople.push(data.userName); $scope.displayOrg.push(data.orgname); I need to pass these arrays from the controller ...