Change the format of JSON with hierarchy