Create json from tree structured data

Hi Everyone,

i am facing a issue while creating json from tree structure data modal in neo4j.

my data as follows:

above graph does not have full data but it is looks like this
in my data each node have same label and different properties.in properties i have a unique BARCODE on which we need to get json data.
each node connected with a node that is node type . this is filter for our graph i need to get node in json that have abc type
currently i am using below query but i am getting General.StackOverFlowError error

MATCH (a:ENTITY)<-[rels:ASSO*]-(b:ENTITY{BARCODE:'x'})
MATCH (a)<-[:Having]-(:ENTITY_TYPE{ENTITY_TYPE_NAME:'abc'})
WITH collect(a) as nodes
With last(nodes) as m
MATCH (l)<-[:Having]-(:ENTITY_TYPE{ENTITY_TYPE_NAME:'abc'})
MATCH PATH = (m)<-[*]-(l)
with collect(PATH) as paths 
call apoc.convert.toTree(paths) yield value return value

i want to get a json which has whle data in json
as a input i can give any barcode from graph

Thanks in advance.