JSONAlchemy and Document fixes

cc @egabancho