func removeIndentFromLists()

in pkg/server/httpserver.go [184:213]


func removeIndentFromLists(bytes []byte) []byte {
	strInput := string(bytes)
	i := strings.Index(strInput, "[")
	j := strings.Index(strInput, "]")
	if i == 0 {
		// the JSON encoding is a list itself, ex: scheduled maintenance events
		// do not process unless the list is an element
		// WITHIN the JSON blob
		return bytes
	}
	for i != -1 && j != -1 {
		// ex: [
		//	"4i20ezfza3p7xx2kt2g8weu2u"
		//	]
		listVal := strInput[i : j+1]
		listValNoFormat := strings.ReplaceAll(listVal, "\t", "")
		listValNoFormat = strings.ReplaceAll(listValNoFormat, "\n", "")

		// replace indented value with unformatted list, ex: ["4i20ezfza3p7xx2kt2g8weu2u"]
		strInput = strings.Replace(strInput, listVal, "", 1)
		strInput = strInput[:i] + listValNoFormat + "," + strInput[i+1:]

		// find the next list element
		listValIndex := strings.Index(strInput, listValNoFormat)
		remainingString := strInput[listValIndex+len(listValNoFormat)+1:]
		i = strings.Index(remainingString, "[")
		j = strings.Index(remainingString, "]")
	}
	return []byte(strInput)
}