import json


def writesJson(markov):
    """Encode Model markov in JSON format and write to string."""
    serial = dict()
    serial['absClasses'] = markov.absClasses
    serial['cumDist'] = list(markov.cumDist.flatten())
    serial['random'] = markov.random.getstate() # can be serialized
    serial['state'] = markov.state
    serial['tMatrix'] = list(markov.tMatrix.flatten())
    serial['ontology'] = markov.ontology
    return json.dumps(serial, indent=4)