Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Json escape

42 views
Skip to first unread message

Florian Térisse

unread,
Dec 16, 2024, 4:27:53 AM12/16/24
to Tasker
Hi,

I send content of notifications to a ws with json format.

I have to escape characters with replacement fonctions for each %evtprm variable :


\\ -> \\\\
\n -> \\n
" -> \"

I use next this variables in my json post message :

{
  "ownerApplication":"%evtprm1",
  "title":"%evtprm2",
   ...
}

There is other solution to format json message easiest ?

Thanks !

aa6vh

unread,
Dec 16, 2024, 10:39:09 AM12/16/24
to Tasker
You can always create a temporary Tasker variable, and set it to the entire json string. The "replacement" can/will be done when creating the temporary Tasker variable. Then just pass that temporary Tasker Variable to json.

Florian Térisse

unread,
Dec 16, 2024, 10:57:29 AM12/16/24
to Tasker
Hi aa6vh

Ok but i want escape just the content of the json attribute values ...
I search a tool like JsonUtils.escape(stringToEscape) for make all replacements in my variable (and not one by one as i do currently ...).

aa6vh

unread,
Dec 16, 2024, 1:55:05 PM12/16/24
to Tasker
You are "escaping" when you are doing the above. Again, you are building the entire json string (including control strings) just prior to sending it out.

Florian Térisse

unread,
Dec 22, 2024, 2:22:17 PM12/22/24
to Tasker
Hi aa6vh,

Sorry but I don't understand...

I create a variable who contains for example 
{
"var1": "%var1",
"var2": "%var2"
}
?

And I use it in my webrequest ?

But how can I escape content of variables %var1 et %var2 ?

Thanks.

aa6vh

unread,
Dec 23, 2024, 10:55:05 AM12/23/24
to Tasker
I don't have the complete code that you are using, but this may work:

{
"var1": %var1,
"var2": %var2
}

Note the lack of quotes around %var1 and %var2. Putting them in quotes just makes a literal "%var1" rather than a Tasker escape string.

Reply all
Reply to author
Forward
0 new messages