json encoder
refs #1060 : move to_dict to base.py
Reconcile the two previous commits (json/to_dict)

Also fix some to_dict move things that were incomplete.
And some PEP8 fixes.