Transform (reformat) JSON structures from one to another using JavaScript