title: Flattening the two different JSON array in Snowflake
body: <p>I have a table with the JSON data as follows.</p>
  <pre><code>|---------------|
  |    JSON_DATA  | 
  |———————————————|
  |     JSON_1    |
  |     JSON_2    |
  |---------------|
  </code></pre>
  <p>JSON_1 Consists the data as follows</p>
  <pre><code>{
      &quot;Money_Earned&quot; : [
          {
             &quot;money&quot; :  2
          }
      ]
  }
  </code></pre>
  <p>JSON_2 Consists the data as follows</p>
  <pre><code>{
      &quot;Money_Spent&quot; : [
          {
             &quot;money&quot; :  3
          }
      ]
  }
  </code></pre>
  <p>Here is my SQL code to retrieve the data from the above table, I'm flattening the JSON array</p>
  <pre><code>SELECT v.value:money as money_earned,
          v2.value:money as money_spent
  FROM TABLE, LATERAL FLATTEN(input =&gt; JSON_DATA: Money_Earned) v, LATERAL FLATTEN(input =&gt; JSON_DATA: Money_Spent) v2
  </code></pre>
  <p>I want the table to be</p>
  <pre><code>|-------------------------------------------------|
  |     MONEY_EARNED       |      MONEY_SPENT       | 
  |------------------------|------------------------|
  |          2             |           0            | &lt;== money_spent 0 because there is not money_spent in JSON_1
  |          0             |           3            | &lt;== money_earned 0 because there is not money_earned in JSON_2
  |-------------------------------------------------|
  </code></pre>
  <p>But I’m getting some other table when I was using the above SQL code. I don’t understand where I’m doing wrong</p>