title: Swift: How to declare a node type which match any arbitrary JSON?
body: <p>Following code loads JSON from a file, and expecting it has an <code>xsd</code> type.</p>
  <pre class="lang-swift prettyprint-override"><code>struct xsd: Decodable {
      var name: String
      var address: String
  }
  
  do {
      if let jsonURL = Bundle.main.url(forResource: &quot;user&quot;, withExtension: &quot;json&quot;) {
          let jsonData = try Data(contentsOf: jsonURL)
          let jsonDecoder = JSONDecoder()
          let persons = try jsonDecoder.decode(xsd.self, from: jsonData)
          print(persons)
          let ii = 7
      }
  } catch  {
      
  }
  </code></pre>
  <p>What if <code>xsd</code> would be more dynamic and it would match any arbitrary JSON in the file?</p>
  <hr />
  <p>How can I define a type which would represent a JSON attribute-key pairs? It should be a recursive structure.</p>
  <p>Here guy define one for HTML. <a href="https://theswiftdev.com/result-builders-in-swift/" rel="nofollow noreferrer">https://theswiftdev.com/result-builders-in-swift/</a></p>
  <p>I would do the same for JSON.</p>
  <p>This is a Node for HTML:</p>
  <pre class="lang-swift prettyprint-override"><code>public struct Node {
  
      public enum `Type` {
          case standard     // &lt;name&gt;contents&lt;/name&gt;
          case comment      // &lt;!-- contents --&gt;
          case empty        // &lt;name&gt;
          case group        // *group*&lt;p&gt;Lorem ipsum&lt;/p&gt;*group*
      }
  
      public let type: `Type`
      public let name: String?
      public let contents: String?
  
      public init(type: `Type` = .standard,
                  name: String? = nil,
                  contents: String? = nil) {
          self.type = type
          self.name = name
          self.contents = contents
      }
  }
  </code></pre>