PuRestJson
PuRestJson copied to clipboard
Proposal for removing quotation marks in value
Quotation marks and backslashes are difficult to handle in PureData world. This patch is a proposal for output value data without quotation marks using code taken here: https://www.appsloveworld.com/c/100/446/how-to-remove-quotation-marks-in-c . Obviously the code proposed here isn't elegant enough to apply yet, the added function could also remove backslashes, but I'm not sure about how to implement it 'cleanly'. Thank you for reading this :).
I am unsure about it for several reasons:
- crashing Pd is not good, but this occasionally happens with other externals as well, take e. g. the infamous [bang( --- [until] combination
- it alters the content of the input and that is often not good, as [print] is usually only used in development, but not to run the program, e. g. in a live performance.
- this should then also be applied to [rest] and [oauth], which can be disastrous, if oauth token or secret are to be obtained by the request and either one contains a quotation mark.
What about a warning in the help files similar to the warning in the [until] help, and the following construct?
[json-decode] [ ] Warning: If you enable this, make sure to run Pd using the -stderr flag to output to command line
| / instead of Pd console, as JSON data may contain special characters that may crash Pd.
| /
[spigot]
|
[print]
Adding a spigot at the 2nd outlet seems quite reasonable, and the warning explanation gives serious hints about how JSON is about in PureData world. For quotation marks and backslashes in value data, I'll build one or two abstractions that uses [list fromsymbol] for my own purposes. May be it would be nice to have this for users that needs to process those data.
- crashing Pd is not good, but this occasionally happens with other externals as well, take e. g. the infamous [bang( --- [until] combination
Note that [bang(--[until] behavior is the same in many other languages with functions like while()
But I suppose that the crash caused by PuRestJSON comes from some inconsistencies between Pd client and Pd server, there have been a lot of progress with those symbols but it's still a bit unstable :-)
I'll build one or two abstractions that uses [list fromsymbol] for my own purposes. May be it would be nice to have this for users that needs to process those data.
https://github.com/patricecolet/pd-abs
I've tested last release, there is no quote marks anymore in value, thanks for this! Works greatly on raspberry with a deken install. I had to compile myself for removing lib dependances on mac m1 though.
When value string contains spaces, there still is the need of an abstraction for transforming the symbol containing spaces to list. Something like this: https://github.com/patricecolet/pd-abs/blob/main/rmBackslash.pd
It is a choice to keep the symbols with spaces as one symbol, and not output a list. The backslash is in it because it is the escape character in tk, so that it is treated as a symbol.
When you use the symbol in your patch, then these are correctly interpreted as one space character, see e.g. the Twitter client example.