cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

How to convert APOC output to table?

bevansound
Node Link

Hi! I am using apoc.coll.frequencies, and I get the following as my output.

[
 {
   "item": "Aboriginal",
   "count": 7
 },
 {
   "item": "Afghan",
   "count": 9
 },
 {
   "item": "Afghani",
   "count": 3
 }
]

I now just want to convert this to a tabular view so I get

(row)	item		count
1	Aboriginal	7
2	Afghan		9
3	Afghani		3

What is the best way to do this?

1 REPLY 1

glilienfield
Ninja
Ninja

Not sure if this is acceptable, but how about an array of arrays, where each element is row in your table?

with [{item:"Aboriginal", count: 7},{item:"Afghan", count: 9},{item:"Afghani", count: 3}] as data
with data, range(0,size(data)-1) as indexes
unwind indexes as index
with [['row', 'item', 'count']]+collect([index+1, data[index].item, data[index].count]) as rows
unwind rows as row
return row