Serializing PSON object to JSON string

Hello
if I have a PSON object something like this:

pson object;
object["key1"] = 55;
object["key2"] = true;
object["key3"] = "hello";
object["key4"] = 3.14;

and I want to convert it to a JSON string so I can to post it to a web URL…

is there any way to do that? because all I didn’t found it in the Protoson docs (https://github.com/thinger-io/Protoson). there is only one method for Serialization and deserialization which used virtual classes that provided methods for writing and reading bytes.

is there any way to do this?

Hi @thespacesiddhesh,

I think that there is not any direct casting, but you can use these variables to feed the json, I mean something like:

    String json;
    StaticJsonDocument<300> doc;
    doc["text"] = String(pson_in["text"]);
    doc["id"] = String(pson_in["id"]);
    doc["status"] = String(pson_in["status"]);
    doc["value"] = (int)pson_in["value"];
 
    serializeJson(doc, json);
    Serial.println(json);

It is not the most scallable way but it should. Note that it is necessary to cast each data when extracted from the pson