edgeToJSON_matrix function

Helper function to convert edges to JSON