Added recursive toJSON() method