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


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...

    {"node":0,"name":"Fremont Brewing"},
    {"node":1,"name":"Holy Mountain Brewing"},
    {"node":5,"name":"Barleywine - American"},
    {"node":6,"name":"Stout - American Imperial / Double"}

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?

Hello @keithave :slight_smile:

Can we set a new property or not?


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.

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.