<p>Is it possible to convert <strong>hierarchical attributes(Map/List)</strong> to <strong>flattened as linear</strong> <code>YAML</code> structure?</p>
<p>For instance, there is a below property defined in a microservice:</p>
<pre><code>default:  
  app:
    authentication: 
      security: ${app.authentication.security}
</code></pre>
<p>The above can be overridden using <code>kube</code> object i.e. configMap and as the above property exposed as <code>${app.authentication.security}</code>, so inside <code>configMap</code> we aren't required to define the entire structure(shown as below), so here we have flattered the <code>YAML</code> hierarchy. We are not required to define the entire order.</p>
<pre><code>app.authentication.security: false 
</code></pre>
<p>Now, is there any possibility to flatter the <code>YAML</code> Map/List, and those <code>Map/List</code> properties can be dynamic. Below is the sample structure.</p>
<p>Example:</p>
<pre><code>app-ex:
  list: 
    - key1: value
      key2: value
      key3: 
        - list1
        - list2
        - list3
    - key4: value
      key5: value
      key6: 
        - list1
        - list2
        - list3
    .
    .
    - key N
</code></pre>
<p>The possible expected output can be a flat pattern as below:</p>
<pre><code>app-ex.list.key1: val1
app-ex.list.key2: val2
</code></pre>

Avinash Mishra
<p>YAML processors can handle and manipulate such files with ease. <a href="https://github.com/kislyuk/yq" rel="nofollow noreferrer">kislyuk/yq</a> could be one choice. Here's a solution with it using <code>tostream</code> to generate path-value pairs, and <code>from_entries</code> to generate the output object:</p>
<pre class="lang-bash prettyprint-override"><code>yq -y '
  [tostream | select(has(1)) | first |= join(&quot;.&quot;) | {key: first, value: last}]
  | from_entries
' file.yaml
</code></pre>
<pre><code>app-ex.list.0.key1: value
app-ex.list.0.key2: value
app-ex.list.0.key3.0: list1
app-ex.list.0.key3.1: list2
app-ex.list.0.key3.2: list3
app-ex.list.1.key4: value
app-ex.list.1.key5: value
app-ex.list.1.key6.0: list1
app-ex.list.1.key6.1: list2
app-ex.list.1.key6.2: list3
</code></pre>
