Unified brtr_node_to_json() and brtr_tree_to_json().