Decode a JSON object of unknown format into a Dictionary with Decodable in Swift 4

Let's pull this apart a little bit, if you don't mind, because I think there's been a bit of correlation here between proposals that I'd like to separate. I'm going to partially reorder your comment to answer sequentially.

The original request for Unevaluated, both partially here, and in SR-5311 is an answer to the currently intractable case of "there is a part of my serialized object graph that I know nothing about, and need to be able to decode without knowing anything about it, for the sake of preserving the values as-is." Usually this comes up when you are decoding parts of a payload whose structure is variable — you need some of the information from it, but not all, and the parts you don't need (and know nothing about) need to be preserved for re-encoding back later on.

The idea here behind Unevaluated is to give you that data, as-is, in a format that may or may not be opaque to you. You can later re-encode the Unevaluated instance, and ideally, get back the same representation that you had before.

This is separate from a request for returning a parsed response in a reasonably consumable format.

This shouldn't be problematic as those types bridge.

This is also no different from manually working with a response from JSONSerialization. You would be getting back the same response, wrapped up in an Unevaluated.

As you say, what would the result of .abstractRepresentation be? How would it be different from the abstract representation contained in an Unevaluated?

This, to me, sounds like the real request here — working with a concrete result type closer to the JSON type I gave an example for in another thread or that @anandabits just posted as well. [This enum is possible today, and relatively easy to put together.]

However, again, I don't think we want to offer types specifically for JSON (especially when they're relatively easy to put together without special internal knowledge). See part of my response upthread to @hooman:

If you need a JSON enum like above, it's possible to write it yourself (and please feel free to use my gist as reference); however, you cannot today write Unevaluated on your own as it requires explicit adoption by JSONEncoder/JSONDecoder.