4 ms·
Very neat. I had a similar need recently which led to a similar solution[^1]. Notably, I used a syntax nearly identical to yours, albeit without the very handy
by tylerchr 6y ago
Very neat. I had a similar need recently which led to a similar solution[^1]. Notably, I used a syntax nearly identical to yours, albeit without the very handy pluggable validators yours has. Nice job.
What led you to choose “!” as the “optional” modifier? My intuition would have guessed that character to have the opposite meaning.
[1]: project: https://github.com/tylerchr/jstn/ https://github.com/tylerchr/jstn/ — playground: https://tylerchr.github.io/jstn/ https://tylerchr.github.io/jstn/
- willvarfar 6y agoA long time ago, before MyPy, I did a python schema checker for JSON. It grew into argument checking too: https://pypi.org/project/obiwan/ https://pypi.org/project/obiwan/ Simple stuff like: Person = { "name": str, "age": int } The basic idea was to use a file full of obiwan types to document the rest api. The schema was both human-readable and valid python. The api could then trivially check the schema. Once the schema is checked, of course, its safe to go walk the json knowing that things aren't going to crash on you etc. It worked great. Still works great. I still prefer the syntax to that of MyPy. No real adoption, of course :) But fun to remember what could have been :)
- wryun 6y agoMy vaguely similar thing - https://wryun.github.io/yajsonschema/ https://wryun.github.io/yajsonschema/