Moves json encoding to the view. Fixes unittests.