Reimplementing the json in count_matrix