json_to_newick.py contains a function, json_to_newick, to convert a json object to newick format.
json - A JSON object. See JSON.
string - A string in Newick format. See Newick format.
>>> json = {
"name" : "F",
"children": [
{"name": "A", "branch_length": 0.1},
{"name": "B", "branch_length": 0.2},
{"name": "E","branch_length": 0.5,
"children": [
{"name": "C", "branch_length": 0.3},
{"name": "D", "branch_length": 0.4}
]
}
]
}
>>> print(json_to_newick(json))
(A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5)F;
By Daniel O'Keeffe