bridge for JSON keys that are illegal method names
jayvdb opened this issue · 1 comments
jayvdb commented
If a key has a hyphen, such as foo-bar
, the resulting bridge property would be illegal in Python, as -
is not legal in method names.
Two ways I can see to fix this.
- Auto voodoo mapping, converting
-
to_
. i.e. jayvdb@019fc68
That has the slight problem that whenfoo-bar
andfoo_bar
exist in the same dict, keyfoo_bar
will be used when the value offoo-bar
is expected. something like legoktm/jsonchecker#16 could be used to sanity check the document before loading it. Before using this approach, we should find any other characters that are legal in JSON keys but not legal in Python method names. e.g.$
,@
, digit as first character. - The other option is to allow the decorator to take a JSON key name as an explicit argument (#7). To me this feels the safer option.
zyga commented
I have to think about this but I also gravitate towards 2.
PS: I've started refreshing my JSON stack. I've started with the validator but I will be back to json-document soon enough. I welcome all bug reports in both projects. Thank you :)