<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Your issue here is Any, which&nbsp;will likely never be Decodable. You’ll need an actual type to contain the raw JSON. Hilariously, I have to wonder if Argo’s JSON enum could be made Decodable, as it can represent every valid JSON type typically contained in the Any returned by JSONSerialization. Yet another reason why Swift needs a real JSON serialization.<div class=""><br class=""></div><div class=""><br class=""></div><div class="">Jon Shier<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 17, 2017, at 10:07 PM, Chris Anderson via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div 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="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="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; 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; 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; 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; 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="" 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="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="font-family: Helvetica;" class=""><br class=""></span></div></div></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>