we often use suffix like :int or :boolean so parameters passed to URL are auto converted to correct python format by the Zope publisher.
This is nice and work in every ways, including JS data variables like "data-myfield:int" or so submitted by JS to call a Zope view.
As far as I can see, there is no :json converter.
Is there a package somewhere implementing it? Would it have sense to include it in the ZPublisher package? What we would like to do is have something like data-myfield:json="{'key1': 'value1', 'key2': 'value2'}" in a HTML content and be managed automatically when passed by JS function to called Zope view. Instead for now we receive a string and need to use json.loads to manage it.
yes indeed I wrote one myself and it works as expected...
from ZPublisher.Converters import type_converters
import json
if 'field2json' not in type_converters:
def field2json(v):
v = json.loads(v)
return v
type_converters['json'] = field2json
Just wondered finally if it worth a PR in ZPublisher too or if it should handle only "real python type" that is not the case for json.
We put it there so it is not enabled by default, you just have to import the package in the init.py of another package : import imio.helpers.converters
I intend to write an issue tomorrow (friday) on the Zope/ZPublisher issue tracker to propose to integrate it there.