Answers: <p>The problem is you're getting an object with <code>index .NetworkSettings.Ports &quot;1234/tcp&quot; 0</code> and in string context that's producing <code>{ 1234}</code> which is a concatenation of the first value (an empty string) joined by a space and the second value which is <code>1234</code>. The index is returning an object. But it's getting stringified. You would never know that without inspecting the return of <code>index</code> with <code>json</code>.</p>
  <p>You can see with</p>
  <pre class="lang-shell prettyprint-override"><code>$ podman inspect evanrox --format '{{ json ( index .NetworkSettings.Ports &quot;1234/tcp&quot; 0 ) }}'
  </code></pre>
  <p>That the result is</p>
  <pre><code>{&quot;HostIp&quot;:&quot;&quot;,&quot;HostPort&quot;:&quot;1234&quot;}
  </code></pre>
  <p>From there you can go</p>
  <pre class="lang-shell prettyprint-override"><code>$ podman inspect evanrox --format '{{ json ( index .NetworkSettings.Ports &quot;1234/tcp&quot; 0 ).HostPort }}'
  </code></pre>
  <p>And then you'll see <code>&quot;1234&quot;</code> drop the <code>json</code>, and you get it</p>
  <pre class="lang-shell prettyprint-override"><code>$ podman inspect evanrox --format '{{ ( index .NetworkSettings.Ports &quot;1234/tcp&quot; 0 ).HostPort }}'
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-05-06T04:21:39.820Z
Answers: 2024-05-06T05:52:48.900Z
Answers: 2024-05-06T05:52:48.900Z
Answers: Evan Carroll
Body: <p>You can set up the test container to inspect with this,</p>
  <pre class="lang-shell prettyprint-override"><code>$ podman run -d -p 1234:1234 --name evanrox alpine:3 sleep 360
  </code></pre>
  <p>When I run the following I get <code>{ 1234}</code> however I want <code>1234</code> (no curly brackets, no spaces). How can I get this with podman/go?</p>
  <pre class="lang-shell prettyprint-override"><code>$ podman inspect evanrox --format '{{index .NetworkSettings.Ports &quot;1234/tcp&quot; 0 }}'
  { 1234}
  </code></pre>
  <p>Again, I just want &quot;1234&quot;</p>
  
Tags: <go><podman>
Title: Go format string produces curly brackets around text value?
UserDisplayName: Evan Carroll
ThreadText: # Go format string produces curly brackets around text value?
  
  (Asked by: username_0 on 2024-05-06)
  
  You can set up the test container to inspect with this,
  
  ```shell
  $ podman run -d -p 1234:1234 --name evanrox alpine:3 sleep 360
  
  ```
  
  When I run the following I get `{ 1234}` however I want `1234` (no curly brackets, no spaces). How can I get this with podman/go?
  
  ```shell
  $ podman inspect evanrox --format '{{index .NetworkSettings.Ports "1234/tcp" 0 }}'
  { 1234}
  
  ```
  
  Again, I just want "1234"
  
  **Tags:** go, podman
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-05-06. Score: 0
  
  The problem is you're getting an object with `index .NetworkSettings.Ports "1234/tcp" 0` and in string context that's producing `{ 1234}` which is a concatenation of the first value (an empty string) joined by a space and the second value which is `1234`. The index is returning an object. But it's getting stringified. You would never know that without inspecting the return of `index` with `json`.
  
  You can see with
  
  ```shell
  $ podman inspect evanrox --format '{{ json ( index .NetworkSettings.Ports "1234/tcp" 0 ) }}'
  
  ```
  
  That the result is
  
  ```
  {"HostIp":"","HostPort":"1234"}
  
  ```
  
  From there you can go
  
  ```shell
  $ podman inspect evanrox --format '{{ json ( index .NetworkSettings.Ports "1234/tcp" 0 ).HostPort }}'
  
  ```
  
  And then you'll see `"1234"` drop the `json`, and you get it
  
  ```shell
  $ podman inspect evanrox --format '{{ ( index .NetworkSettings.Ports "1234/tcp" 0 ).HostPort }}'
  
  ```
  
  
  ---
  
  