Refactoring for arrays in json objects