zyga/json-document

bridge for JSON keys that are illegal method names

jayvdb opened this issue · 1 comments

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.

  1. Auto voodoo mapping, converting - to _. i.e. jayvdb@019fc68
    That has the slight problem that when foo-bar and foo_bar exist in the same dict, key foo_bar will be used when the value of foo-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.
  2. 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 :)