fixed recursion in toJson