rfid reading function returning null I have a function that reads rfid card and return rfid string. Function reads string well but.
I am using ArduinoJson libray to generate json .
this is the function that i am using to read rfid cards.
String rfidOku(){
  String kartid= &quot;&quot;;
  if( mfrc522.PICC_IsNewCardPresent() &amp;&amp; mfrc522.PICC_ReadCardSerial()){
    for (byte i = 0; i &lt; mfrc522.uid.size; i++) 
    {
        kartid.concat(String(mfrc522.uid.uidByte[i] &lt; 0x10 ? &quot; 0&quot; : &quot; &quot;));
        kartid.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    kartid.toUpperCase();
    //Serial.println(kartid); 
  }
  kartid.trim();
  return kartid;
}

and in the loop function , if button pressed i am getting an rfid and ı am creating json using it
    const size_t capacity = JSON_OBJECT_SIZE(4);
    DynamicJsonDocument doc(capacity);
    const String str_rfid = rfidOku();              
    doc[&quot;id&quot;] = odeme.id;
    doc[&quot;fiyat&quot;] = odeme.fiyat;
    doc[&quot;rfid&quot;] = str_rfid;

    serializeJson(doc, Serial);  

When i look to serial monitor rfid field is null. Why it happens. I tried to write other string there it works well with other string but why it does not with str_rfid.
I also print value of str_rfid using Serial.print str_rfid getting rfid card id from function well.
It could be your JSON object capacity is too small because of string duplication when you deserialise it to print it.
You should try a capacity like JSON_OBJECT_SIZE(3) + 500 for deserialising, and see what happens.
Also, try: doc[&quot;rfid&quot;] = str_rfid.c_str(); to see if that works better (CString instead of String object).
More information on object capacity can be found here; there's a calculator here.