fixed error in to-json function, added tests