Added array support in `toJson` method