Finish the toJson function.