<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Say I have a JSON object such as:<div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class="">&nbsp;&nbsp;{</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; "id": "4yq6txdpfadhbaqnwp3",</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; "email": "<a href="mailto:john.doe@example.com" class="">john.doe@example.com</a>",</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; "name":"John Doe",</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; "metadata": {</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; "link_id": "linked-id",</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; "buy_count": 4</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class="">&nbsp; }</div></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica;" class="">And with a struct of:</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><div style="font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">struct</span> User: <span style="color: #703daa" class="">Codable</span> {</div><div style="font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class="">&nbsp; <span style="color: #ba2da2" class="">var</span> id: <span style="color: #703daa" class="">String</span></div><div style="font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class="">&nbsp; <span style="color: #ba2da2" class="">var</span> email: <span style="color: #703daa" class="">String</span></div><div style="font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class="">&nbsp; <span style="color: #ba2da2" class="">var</span> name: <span style="color: #703daa" class="">String</span></div><div style="font-family: Menlo; color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><span style="color: rgb(0, 0, 0);" class="">}</span></div><div style="font-family: Menlo; color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class="">How can I decode the `metadata` field into a Dictionary?</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">I’ve tried doing things such as, in my struct,</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(186, 45, 162);" class="">var</span><span style="font-family: Menlo;" class="">&nbsp;</span><span style="font-family: Menlo;" class="">metadata:</span><span style="font-family: Menlo;" class="">&nbsp;</span><span style="font-family: Menlo; color: rgb(112, 61, 170);" class="">Dictionary</span></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">or</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(112, 61, 170);" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(186, 45, 162);" class="">var</span><span style="font-family: Menlo;" class="">&nbsp;</span><span style="font-family: Menlo;" class="">metadata:</span><span style="font-family: Menlo;" class="">&nbsp;</span><span style="font-family: Menlo; color: rgb(112, 61, 170);" class="">[String: Any]</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(112, 61, 170);" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class="">But I get the error&nbsp;</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">MyPlayground.playground:3:7: note: cannot automatically synthesize 'Encodable' because '&lt;&lt;error type&gt;&gt;' does not conform to&nbsp;'Encodable'</div><div style="margin: 0px; line-height: normal;" class="">&nbsp;&nbsp;var metadata: Dictionary<span style="font-family: Menlo; color: rgb(112, 61, 170);" class="">&nbsp;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(112, 61, 170);" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class="">A meta or metadata field on many APIs (such as <a href="http://www.stripe.com" class="">www.stripe.com</a>) can contain whatever you want, and I still want to be able to process it on the Swift end. How can I store that meta data field into a Dictionary that I can parse apart manually after?</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Thanks!</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Chris Anderson</div><div class=""><span style="font-family: Menlo; color: rgb(112, 61, 170);" class=""><br class=""></span></div></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></div><div class=""><br class=""></div><div style="font-family: Menlo;" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica;" class=""><br class=""></span></div></div><div style="font-family: Menlo; color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><div class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica;" class=""><br class=""></span></div></div></div></body></html>