roll up a tree into a JSON document