Form proper groups JSON for API. see #27