In our app, we have chosen the Pair class to demonstrate its usage. The Pair is also a data class. Consider the following line of code:
data class Pair<out A, out B> : Serializable
It represents a generic pair of two values. You can look at it as a key–value utility in the form of a class. We need to create a JSON object of a number of online users with the list of their nicknames. You can create a JSON object with the help of a Pair class. Take a look at the following lines of code:
val userJoinedData = json(Pair("numOfUsers", numOfUsers), Pair("nickname", nickname), Pair("usersList", usersList))
The preceding JSON object will look like the following piece of code in the JSON format:
{ "numOfUsers": 3, "nickname": ...