Uploaded image for project: 'Swift'
  1. Swift
  2. SR-5311

Allow JSONDecoder to somehow provide loose JSON structure

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler, Standard Library
    • Labels:
      None

      Description

      I have an API, which is mostly strongly typed, but has some part that has a JSON dictionary, with arbitrary elements, which could be used for debugging purposes. At first I tried to map this to my Decodable type via a property of Dictionary type String: Decodable but this didn't work, because swift needs more type info. I then came up with the attached enum for representing a random JSON structure, sort of similar to what NSJSONSerialization provides (see below).

      I assume the JSONDecoder has a representation of this structure already.
      Could something like this be obtained from the JSONDecoder somehow?
      Suggestion would be let Decoder have a typealias CanonicalStructure = JSONValue and a the singleValueContainer have a decoder.decodeCanonicalStructure() throws ?

      Here's my quick idea for such a structure https://gist.github.com/hannesoid/10a35895e4dc5d6f1bb6428f7d4d23a5

        Attachments

          Activity

            People

            Assignee:
            itaiferber Itai Ferber
            Reporter:
            hannesoid Hannes Oud
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: