JsonParserGeneratorRK with for loop and different value names for every entry

Hey all,

I want to use a for loop to add data to the json structure:

JsonWriterStatic<256> jw;
    {
      JsonWriterAutoObject obj(&jw);

      for (uint8_t j = 0; j < VALUES; j++)
      {
        jw.insertKeyValue("value_name", dataArray0[0][j]);
      }

    }

This works as expected. My question now is if there is a way that I can also change the value name inside the for loop? Right now, every value would be named the same.

Thanks in advance
Tim

If you want to include a number in the key, using snprintf is the easiest way:

 	  for (uint8_t j = 0; j < VALUES; j++)
      {
		char name[32];
		snprintf(name, sizeof(name), "value%d", j);  
        jw.insertKeyValue(name, dataArray0[0][j]);
      }

This will create keys of the format value0, value1, …

However you may prefer to use an array instead of an object with indexed keys. But both work.