Looking up data by key in Hugo with a string : <p>I'm trying to create a HUGO-based API documentation site which reads JSON schemas, and prints them in HTML.</p>

<p>I'm almost there, but I'm stumped on how exactly to pass in the data I want to a partial. </p>

<p>Given a standard JSON schema file, such as the following:</p>

<pre><code>{"paths": {
  "/auth/login": {
    "get": {
    "operationId": "login",
    "responses": {
      "200": {
        "description": "",
        "schema": {
          "ref": "#/definitions/loginResponse"
        }
      }
    }
  },
},
"definitions": {
  "loginResponse": {
    "type": "object"
  }
}}
</code></pre>

<p>I'd like to display the details of that path, and then render a partial using the schema definition in "ref". I found a way to read that ref param and parse it into a reference for the definition. "Target" below looks like:</p>

<blockquote>
  <p>Target: .definitions.loginResponse</p>
</blockquote>

<pre><code>{{ range $path, $methods := .paths }}
  &lt;h4&gt;{{ $path }}&lt;/h4&gt;

  {{ range $method, $items := $methods }}
    &lt;h5&gt;{{ $method }}&lt;/h5&gt;
    &lt;ul&gt;
      {{ range $status, $info := .responses }}
        &lt;li&gt;
          &lt;div&gt;{{ $status }}&lt;/div&gt;
          &lt;h6&gt;Ref: {{ $info.schema.ref }}&lt;/h6&gt;
          &lt;p&gt;Target: {{ $target := (printf ".definitions.%s" (index (findRE "[^/]+(/?$)" $info.schema.ref) 0))}}&lt;/p&gt;
          &lt;div&gt;{{ partial "schema" $target }}&lt;/div&gt;
        &lt;/li&gt;
      {{ end }}
    &lt;/ul&gt;
  {{end}}
{{end}}
</code></pre>

<p>The trouble is, <code>$target</code> is a string. In Javascript, I'd just be able to pass it in as a key to get that object param: <code>schema["definitions.loginResponse"]</code>.</p>

<p>No such luck in HUGO, however. I simply can't find a way to go from that target key string to the actual param. </p>

<p>Help! Am I missing something obvious? Am I going about this all wrong?</p>
