Auto Discovery MQTT message in JSON not working with Arduino IDE

Hello, I am trying to publish a JSON message to my MQTT server.

Here is how I am trying to send :

if (client.connect((char*) clientName.c_str(),  mqttUser, mqttPassword)) {
        Serial.println("connected");
        StaticJsonDocument<500> JSONbuffer;
        JsonObject JSONencoder = JSONbuffer.to<JsonObject>();

        JSONencoder["name"] = "Hall Computers Master";
        JSONencoder["command_topic"] = "office/switch/hall/computer/state";
        JSONencoder["state_topic"] = "office/switch/hall/computer/state";

        char JSONmessageBuffer[500];
        serializeJson(JSONbuffer, JSONmessageBuffer);        

        Serial.println(JSONmessageBuffer);

        client.publish(topic1_config, JSONmessageBuffer);
        client.publish(topic1_state, "ON");
        client.subscribe(topic1_state);
      } else {
        Serial.print("failed with state ");
        Serial.print(client.state());
        delay(100);
      }

With all that as well. I can get serial.println exactly how it should be. But not able to send the publish message on the topic. I don’t know where I am wrong. Although my below client.publish(topic1_state, "ON"); works very well every time.

Just not able to send the JSON payload.

Thank you! (In advance)

I got the solution. I need to increase the size of MQTT_MAX_PACKET_SIZE from 128 to 1024 in PubSubClient.h