Check out example codes for "swift convert dictionary to json". It will help you in understanding the concepts better.

Code Example 1

let dic = ["2": "B", "1": "A", "3": "C"]
let encoder = JSONEncoder()
if let jsonData = try? encoder.encode(dic) {
    if let jsonString = String(data: jsonData, encoding: .utf8) {
        print(jsonString)
    }
}

Learn ReactJs, React Native from akashmittal.com