title: how to create a struct/model in golang with dynamic/arbitrary fields
body: <p>Is it possible to create a struct with dynamic/arbitrary fields and values?</p>
  <p>My app will receive request with JSON body:</p>
  <pre><code>{
  &quot;Details&quot;: {
    &quot;Id&quot;: “123”,
   },
  &quot;Event&quot;: {
    &quot;Event&quot;: &quot;Event&quot;,
   },
  “RequestValues”: [
    {
      “Name&quot;: &quot;Name1&quot;,
      &quot;Value&quot;: &quot;Val1&quot;
    },
    {
      &quot;Name&quot;: &quot;Name2&quot;,
      &quot;Value&quot;: 2
    },
    {
      &quot;Name&quot;: “Foo”,
      &quot;Value&quot;: true
    }
      ]
    }
  </code></pre>
  <p>This will be unmarshalled to my model 'Request':</p>
  <pre><code>type Request struct {
      Details         Details          `json:&quot;Details&quot;`
      Event           Event            `json:&quot;Event&quot;`
      RequestValues []RequestValues    `json:&quot;RequestValues&quot;`
  }
  
  type Details struct {
      Id     string `json:&quot;Id&quot;`
  }
  
  type Event struct {
      Event      string `json:&quot;Event&quot;`
  }
  
  type RequestValues struct {
      Name  string `json:&quot;Name&quot;`
      Value string `json:&quot;Value&quot;`
  }
  </code></pre>
  <p>I have to re-map model 'Request' to a new model 'Event' with arbitrary fields in &quot;Values&quot;. After marshalling new re- mapped model 'Event' I should get this JSON output that corresponds to the request:</p>
  <pre><code>{
  &quot;Event&quot;: &quot;Event&quot;
  &quot;Values&quot;: {
    “Id&quot;: &quot;123&quot;,      &lt;= non arbitrary mapping from Request.Detail.Id
    &quot;Name1&quot;: &quot;Val1&quot;,  &lt;= arbitrary 
    &quot;Name2&quot;: 2,       &lt;= arbitrary
    “Foo”: true       &lt;= arbitrary
  }
  </code></pre>
  <p>}</p>
  <p>Arbitrary values will be mapped from &quot;RequestValues&quot;. Names of those fields should be the values of Request.RequestValues.Name and their values should be the values of Request.RequestValues.Value</p>
  <p>Here is my 'Event' model:</p>
  <pre><code>type Event struct {
      Event             string `json:&quot;Event&quot;`
      Values            Values `json:&quot;Values&quot;`
  }
  
  type Values struct{
      Id      string  `json:&quot;Id&quot;`
  }
  </code></pre>