Realm Object to Json


How can i convert Realm Object to below format

“latitude”: 40.783826,
“longitude”: 73.975363,
“actual_speed”: 40,
“accuracy”: 0,
“activity_type”: “stop”
“started_at”: “2018-07-24T06:49:26.562Z”,
“ended_at”: “2018-07-24T06:49:26.562Z”,
“offline”: true
“geo_encoded_ployline”: “[email protected]~Nse”,
“offline”: true,
“activity_type”: “walking”,


This looks like an array of the same json object (using a nosql database)

It looks like it has the following structure :slightly_smiling_face:

let latitude = RealmOptional<Float>() // use latitude.value to get number
let longitude = RealmOptional<Float>() // use longitude.value to get number
let actual_speed = RealmOptional<Int>() // use actual_speed.value to get number
let accuracy = RealmOptional<Float>() // use accuracy.value to get number
@objc dynamic var activity_type: String? = nil
@objc dynamic var started_at: Date = Date() // required. records start time of activity
@objc dynamic var ended_at: Date? = nil // optional. record end time within code
@objc dynamic var geo_encoded_ployline: String? = nil
@objc dynamic var offline = true // required. change if user goes offline

Link to documentation