cancel
Showing results for 
Search instead for 
Did you mean: 

Add Zero-Based 'Property' in JSON Exported File Through Query

keithave
Node Clone

Howdy,

I'm going to try asking this question a different way...

Using strictly a cypher query or apoc procedure, I want to output a json file to be readable for a D3 Sankey display. My json file must contain zero-base numbering. I cannot use the existing node IDs, as those do not follow the required zero-base convention.

The output of this query should look like this...

    {
        "nodes":[
    {"node":0,"name":"Fremont Brewing"},
    {"node":1,"name":"Holy Mountain Brewing"},
    {"node":2,"name":"Bourbon"},
    {"node":3,"name":"Cognac"},
    {"node":4,"name":"Altbier"},
    {"node":5,"name":"Barleywine - American"},
    {"node":6,"name":"Stout - American Imperial / Double"}
    ],
    "links":[
    {"source":0,"target":2,"value":1},
    {"source":2,"target":4,"value":1},
    {"source":0,"target":3,"value":1},
    {"source":3,"target":5,"value":1},
    {"source":1,"target":3,"value":1},
    {"source":3,"target":6,"value":1}
    ]}

I want to add the zero-based number through the query/procedure, not have it pre-existing as a property.
What would I need to add to my query to 'inject' this kind of zero-based numbering? Or is there an APOC procedure which would 'inject' a zero-based number per node & source/target as seen in the example above?

3 REPLIES 3

Cobra
Ninja
Ninja

Hello @keithave

Can we set a new property or not?

Regards,
Cobra

Hi @Cobra thank your for your response/question.
I don't think adding a new property can be done in a way to satisfy the zero-based sankey json req. Even if I were to create a new property of {node: 0} etc, there are 3 different node types/labels at play here (:Brewery), (:BarrelAged), (:BeerType) and they only make their way into the json/sankey IF a beer (that's a different node type but doesn't go into the json file) is actually barrel-aged and IF there are more than 1 beers barrel-aged by the same brewery. So for all of the 3 node types that would make their way into the json file, the zero-based numbering would need to be monitored/done manually so there wouldn't be any gaps in the numbering for the select sub-set amount of nodes within each label category.
The D3 sankey formatting I'm trying to use requires an in-order numbering from 0 to n (no gaps) of any of the objects pulled into the json file. There are also sankey diagrams based on name and I may go that route, but I like the versions of sankey examples I see based on numbering better. Some folks have done some sort of post-cypher javascript numbering, but I'm hoping to avoid that.
That's why I was hoping there was an APOC procedure for adding zero-based numbering on the output of a json file.

Cobra
Ninja
Ninja

With d3.js you won't have to change ids normally. Otherwise you should do this operation in JS, I have no solution right now to make it in Cypher.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.