Fixesi bugs in JSON and tree generation