No more trailing comma after last item in array

The original script wrote a comma at the end of each line in the array. The comma after the last item generated an error in Zabbix. The discovery rule showed the status Not supported and the error was "Value should be a JSON object". I've added an if statement to check whether the item is the last item in the array and print the line with or without a trailing comma accordingly.