Extract a command from a JSON message

Can anyone help extract a simple command from a JSON MQTT message received from IoT Platform in Arduino please?

#include <ArduinoJson.h>

//sample payload {“status”:“on”} which I can print

Code in my callback function which doesn’t do anything other than print a 0
String inData;
JsonObject& root = jsonBuffer.parseObject(inData);
String command = root[“status”];
Serial.println(command);

originating work:

 String inData;
  JsonObject& root = jsonBuffer.parseObject(inData);

You are (apparently) trying to parse and empty string. No one you don’t get anything.

thanks to John M for this //sample payload {"status":"on"}

payload[payloadLength] = 0; //Add nul terminator String inData = String((char *)payload); JsonObject& root = jsonBuffer.parseObject(inData); String command = root["status"];

Still curious how we might pull status from a message like {"d":{"status":"on"}}..

Still curious how we might pull status from a message like {“d”:{“status”:“on”}}…

The name “status” is NOT at the root level. It is an element of the array that is the value of the “d” object.

Something like this MIGHT work:

   JsonObject &stat = root["d"];

   String on = stat["status"];

I’m not familiar with the ArduinoJson library’s methods, but that is how I get the value associated with status using the JSON parser code I am familiar with.