title: How to post null values in JSONSerialization parameters if some of the variables are nil in swift?
body: <p>my code looks like this. I've around 10 parameters and some of the values can be nil and if the values are nil, I need to http post those nil values as null.</p>
  <pre><code>func someFunc(userId: Int, param1: String?, param2: String?, param3: String?, completion: @escaping (_ response: [String: Any]) -&gt; Void) {
  
          let url = URL(string: &quot;api-endpoint&quot;)
          let parameters: [String: Any] = [&quot;id&quot;: userId, &quot;param1&quot;: param1, &quot;param2&quot;: param2, &quot;param3&quot;: param3] //here's the params can be nil.
          var request = URLRequest(url: url!)
          request.httpMethod = &quot;POST&quot;
          request.setValue(&quot;Application/json&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)
          guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: []) else {
              return
          }
     request.httpBody = httpBody
          let session = URLSession.shared
          session.dataTask(with: request) { (data, response, error) in
              if let data = data {
                  do {
                      let json = try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
                      completion(json)
                  } catch let err {
                      print(err.localizedDescription)
                  }
              }
          }.resume()
      }
  </code></pre>