<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Aug 22, 2017, at 12:32 PM, Youming Lin via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="divtagdefaultwrapper" dir="ltr" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class=""><div style="margin-top: 0px; margin-bottom: 0px;" class="">Hi all<br class=""><br class="">With Swift 4 Codable support, we can now do the following conversions:</div><p style="margin-top: 0px; margin-bottom: 0px;" class=""></p><ol style="margin-bottom: 0px; margin-top: 0px;" class=""><li class=""><span style="font-size: 12pt;" class=""></span>Codable <-> Data using JSONEncoder/JSONDecoder<br class=""></li><li class="">Any <-> Data using JSONSerialization</li></ol><div class=""><br class=""></div><div class="">Not sure if I missed something obvious, but is there a simple way to do Codable <-> Any conversions?</div><p style="margin-top: 0px; margin-bottom: 0px;" class=""></p><div style="margin-top: 0px; margin-bottom: 0px;" class=""></div></div></div></blockquote><br class=""></div><div>Well, any type can be cast to `Any`, but I don't think that's what you have in mind.</div><div><br class=""></div><div>What exactly do you want to do? Convert arbitrary types into the arrangement of strings, numbers, bools, arrays, and dictionaries that JSON would use, but not actually serialize that out to JSON? There's nothing built-in that will do that, but you can either apply JSONEncoder to make a Data and then JSONSerialization to decode it back into that data structure, or write a custom coder that mimics the JSONEncoder. Since JSONEncoder and JSONDecoder are open source, you could even use their source code as a starting point.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class=""><div style="font-size: 12px; " class="">-- </div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>
</div>
<br class=""></body></html>