Including " as a delimiter character in event data string[Solved]

I am trying to send an event with data string that is structured JSON like;


I had a look on Stackoverflow and the 2 approaches suggested were to use “” or "

I am using a String::format() to format the data string and to insert the " characters. I have tried “” and " - unfortunately neither of these work.

Any suggestions as to make this work?

Hi @armor. I have assumed you are asking how to embed a " character in a string within particle code.
I used the " (backslash) before the inserted " character.
This worked for me.

See code fragment below:

    String message = "{\"SMSTokString\": \"Bearer ";
    message.concat("\", \"body\": \"");

This successfully produces a string containing the " characters.

I dont know about the string::format() command and how this might differ.
Hope this helps

Thanks for your help. When I follow the approach you have suggested (dataStr is declared as a String!)

    dataStr = "\"Param_TimerP\",";

the event is received like this;


This is where I started!

If you are using String::format() you needn’t use concat() - just do it in one go

    dataStr = String::format("\"Param_TimerP\",\"%3d\"",param.timerPeriod);

And for the embedded escaped double quotes don’t mind them.
Just have a look at the actual string via


BTW, what’s your target for that data? I’d think JSON key value pairs usually should be connected with colons (:) and individual pairs separated with commas (,).




This was exactly what I did first however " are showing in the CLI rather than " when I do a Particle Subscribe Mine. Is that the issue i.e. if I output to Serial with print it will appear OK?

In answer to your BTW - I have been asked to output the events in the following JSON like format:

1.	"data":"{
           "variables": {

The Particle CLI prints the event as a JSON object. For example:


Because the event data is represented as a string in the event object, any JSON characters in the string have to be escaped. Thus it shows as {\"a\":123} when it’s printed, but if you use that event data from something that understands JSON, like webhooks, or a node.js script, it’s handled properly. In other words, this is what a webhook would see:


@rickkas7 Thanks for explaining that behaviour of the CLI. Problem Solved


Glad you were able to get it fixed @armor, thanks everyone for the help!

@armor, what Rick explained there was what I meant when I said that :wink:

and if you checked

you might have seen the actual string

1 Like

No Worries! Just pleased to be getting on with things - I thought I had it the first time.

1 Like