Remove reverse solidus \ and quotation mark " in message after dict.serialize @mode json from dict.pack

Sébastien's icon

Hi! I am having a problem with boolean value with a maxurl object. So I am trying this thing to see if I can find a work around by using a dict.pack object and formatting it with dict.serialize @mode json.

For exemple here is the result in a message object:
"{
    \"on\" : \"true\",
    \"hue\" : 43960,
    \"sat\" : 217,
    \"bri\" : 135
}
"
I want to get rid of the reverse solidus \ and quotation mark " around the \"true"\ value. The final dict editor takes into account the carriage return \n and the horizontal tab \t but it's not causing any error if I remove manually the \ and " around the true (or false) value. When removed It seems to work for what I need.

So the desire output would be:
"{
    \"on\" : true,
    \"hue\" : 43960,
    \"sat\" : 217,
    \"bri\" : 135
}
"
Is there any way to parse and remove the specifics characters. I would imagine that it could be feasible with regex, but it's not my forte. Does anyone have a tip or two?

Thank you

dict_test.maxpat
Max Patch
Sébastien's icon

I am trying to get around this with regexp. But I get stuck with a comma at the end of my instruction.
ThatLastComma: { "on":true, "hue":33333, "sat":200, "bri":127, }

Max Patch
Copy patch and select New From Clipboard in Max.

Ben Bracken's icon

Just a note here, there is no such thing as a boolean data type in Max, so it will always be converted to 0/1 in dict. Maybe you can just use 0/1 to start off with? Not sure if that is helpful for you.

Otherwise, I'd look at zl.slice to separate the things you want commas added to and the things you don't want commas added to, then joining them on the other side.

-Ben

keepsound's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Try this...add a token and then remove it, but maybe there's a space after the comma, see if it's working.

Sébastien's icon