String variables in Operate/Zeebe

Hi,
I’m starting a new process instance with the zbctl in this way:

zbctl create instance MyProcess --variables “{"myVar":"myVal"}”

(the " are escaped, but the forum form parser is removing the back slashes)

The process is started correctly.
When I check in Operate I see there’s my variable assigned to the process instance with the double quotes.
Also checking the variables operate api calls in the network section of my browser shows 2 double quotes

So my question is, how is the string saved? Is it saved with double quotes?

Of course I can’t start a process instance in this way:

zbctl create instance MyProcess --variables “{"myVar":myVal}”

Thanks for your help!
Enrico

Hello @Enrico ,

string variables are saved as JSON strings. A json String is always surrounded by double quotes in textual representation, however, as soon as you fetch variables, you will receive:

{"myVar":"myVal"}

Jonathan

Thanks @jonathan.lukas , this makes sense.
What is confusing me is the response of the Operate api call, where I see the text surrounded by two double quotes: ""myVal""
Maybe the first " is added by operate and the second one is related to the json string?

I’ve also executed a variables search by value with Operate api, and in the filter I must provide the double quotes to fetch the data:

Hello @Enrico ,

this is because the variables are always provided as JSON string and have to be parsed to become a “real” json object.

In JS for example, you would use

JSON.parse(response.items[0].value)

to receive the actual value of the variable.

The reason is that the value could be any of the 6 JSON types which would make the value field various in typing.

In the end, the parsing of the value is left to the client and the API will always respond with a string.

Jonathan

1 Like