Arborjs reading json data form php via json_encode

387 views Asked by At

I am trying to export some data from a php script to load into arborjs, problem is the php json_encode encapsulates the node and edge objects in square brackets [], which upsets arborjs.

json_encode gives:

{"nodes":[{"10":{"auth":"EP","depth":0}}]}

but arborjs wants

{"nodes":{"10":{"auth":"EP","depth":0}}}

Anyone else encountered and solved it?

1

There are 1 answers

0
bentwonk On BEST ANSWER

Issue was with array_push

$n=array($key=>$value);
array_push($array,$n);

does not preserve keys, instead using:

array_push($array[$key]);
$array[$key]=$value;

works, preserving keys.