Fixed a JSON encode bug

Fixed the problem if the first field in an aggregate is optional and
not present, an extra comma would be encoded.