Re:Arguments against JSON-driven development
by StavrosK on Thursday August 25, 2016 @11:06AM
(#12359553)
Yeah, this is currently pretty bad in Python, which led me to create the jsane library:
https://pypi.python.org/pypi/jsane
>>> j = jsane.loads('{"foo": {"bar": {"baz": ["well", "hello", "there"]}}}')
>>> j.foo.bar.baz[1].r()
u'hello'
Re:Arguments against JSON-driven development
by Roboprog on Thursday August 25, 2016 @12:31PM
(#12360358)
Simple rule of thumb: Don't Repeat Yourself. If part of the data structure is accessed in multiple places, create a wrapper routine (or even an object/class) around it. Otherwise, if it's in one place, perhaps "You Aren't Gonna Need It".
In JavaScript, a simple thing that helps is to use lodash.get and provide a path to the property you are wanting.
If the path isn't there, the lodash.get returns undefined. This is much nicer than getting the error "Cannot read property 'to' of undefined" when "path" isn't there.