refractored matrix for json