title: How to save the JSON data to UserDefault in Swift?
body: <p>I made a post request using Alamofire. This is my code to fetch data from server using an endpoint:</p>
  <pre><code>    Alamofire.request(&quot;http://192.168.80.21:3204/api/auth/signin&quot;, method: .post, parameters: parameters,encoding: JSONEncoding.default, headers: nil).responseJSON {
          response in
          switch response.result {
          case .success(let value):
              let json = JSON(value)
              print(json)
  
              break
          case .failure(let error):
              print(&quot;Error :- \(error)&quot;)
          }
      }
  }  
  </code></pre>
  <p>And this is the data i get from the server:</p>
  <pre><code>{
    &quot;accessToken&quot; : &quot;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NTIsInJvbGUiOjEsImlhdCI6MTYwMzg2ODUxNCwiZXhwIjoxNjAzOTU0OTE0fQ.y68w8XQfqFZDVgaxiuFuVCOqaI5e5vZ-SfoDB_Ctxro&quot;,
    &quot;role&quot; : &quot;admin&quot;,
     &quot;auth&quot; : true
  }
  </code></pre>
  <p>I want to save the response to UserDefault for further use. Help me to save the data to Userdefault and retrieve and print data.</p>