I'm trying to send a JSON to a ESP32 and set the value to a variable, for the first 3 variables it works fine, but for some reason it skips the last one. Right now it's sent in an array, but when it's not in an array and I make it a JSONObject instead of a JSONArray it even skips the last 2 values.
When trying a hardcoded JSON it works fine though.
Here is the code:
#include <Arduino.h>
#include <EEPROM.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <NeoPixelBus.h>
#include <AsyncJson.h>
#include <ArduinoJson.h>
#define EEPROM_SIZE 512
const int powerStateAddress = 0;
const int groupNumberAddress = 2;
const uint16_t pixelCount = 82;
const uint pixelPin = 17;
const uint relayPin = 26;
const char* ssid = "";
const char* password = "";
AsyncWebServer server(80);
const size_t jsonCapacity = JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + 70;
int powerState;
int groupNumber;
int colorSaturation = 255;
int greenValue;
int redValue;
int blueValue;
int whiteValue;
NeoPixelBus<NeoGrbwFeature, NeoEsp32I2s1800KbpsMethod> strip(pixelCount, pixelPin);
RgbwColor green(colorSaturation, 0, 0, 0);
RgbwColor red(0, colorSaturation, 0, 0);
RgbwColor blue(0, 0, colorSaturation, 0);
RgbwColor white(0, 0, 0, colorSaturation);
RgbwColor black(0);
void setGroupNumber(DynamicJsonDocument json) {
  groupNumber = json["groupNumber"];
  EEPROM.write(groupNumberAddress, groupNumber);
  EEPROM.commit();
}
void setColor() {
  for(uint16_t pixel = 0; pixel < pixelCount; pixel++) {
    strip.SetPixelColor(pixel, RgbwColor(greenValue, redValue, blueValue, whiteValue));
  }
}
void setColorValues(DynamicJsonDocument json) {
  JsonArray colorValues = json["colorValues"];
  if(greenValue != colorValues[0]) {
    greenValue = colorValues[0];
  }
  if(redValue != colorValues[1]) {
    redValue = colorValues[1];
  }
  if(blueValue != colorValues[2]) {
    blueValue = colorValues[2];
  }
  if(whiteValue != colorValues[3]) {
    whiteValue = colorValues[3];
  }
  setColor();
}
void setBrightness(DynamicJsonDocument json) {
  colorSaturation = json["brightness"];
  setColor();
}
DynamicJsonDocument parseData(AsyncWebServerRequest *request, uint8_t *data, String endpoint) {
  DynamicJsonDocument doc(jsonCapacity);
  DeserializationError err = deserializeJson(doc, data);
  Serial.println(serializeJson(doc, Serial));
  if(err) {
    request->send(400, "text/plain", "err on" + endpoint);
  } else {
    request->send(200, "application/json", "{'msg': 'OK'}");
  }
  return doc;
}
void setup() {
  Serial.begin(115200);
  while(!Serial) {}
  EEPROM.begin(EEPROM_SIZE);
  if(EEPROM.read(powerStateAddress) == LOW || EEPROM.read(powerStateAddress) == HIGH) {
    powerState = EEPROM.read(powerStateAddress);
    if(powerState == HIGH) {
      digitalWrite(relayPin, HIGH);
    }
  } else {
    powerState = LOW;
    EEPROM.write(powerStateAddress, powerState);
    EEPROM.commit();
  }
  if(EEPROM.read(groupNumberAddress) != 255) {
    groupNumber = EEPROM.read(groupNumberAddress);
  }
  WiFi.begin(ssid, password);
  while(WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(250);
  }
  Serial.println(WiFi.localIP());
  server.on("/controller/setGroup", HTTP_POST, [](AsyncWebServerRequest *request) {}, NULL, 
  [](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
      DynamicJsonDocument doc = parseData(request, data, "/setGroup");
      setGroupNumber(doc);
  });
  server.on("/controller/setColor", HTTP_POST, [](AsyncWebServerRequest *request) {}, NULL, 
  [](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
    DynamicJsonDocument doc = parseData(request, data, "/setColor");
    setColorValues(doc);
  });
  server.begin();
}
void loop() {
  Serial.println(powerState);
  Serial.println(EEPROM.read(powerStateAddress));
  Serial.println(groupNumber);
  Serial.println(EEPROM.read(groupNumberAddress));
  Serial.print("Brightness: ");
  Serial.println(colorSaturation);
  Serial.print("green: ");
  Serial.println(greenValue);
  Serial.print("red: ");
  Serial.println(redValue);
  Serial.print("blue: ");
  Serial.println(blueValue);
  Serial.print("white: ");
  Serial.println(whiteValue);
  Serial.println("---------");
  delay(2000);
}
Here is the JSON that I send:
    "colorValues": [
        255,
        255,
        255,
        255
        ]
}
This is what the ESP32 receives:
{"colorValues":[255,255,255,255]}33
And this is the result:
green: 255
red: 255
blue: 255
white: 0
 
    