title: Dynamic table from nested JSON data
body: <p>Trying to solve the issue with iteration of nested JSON,
      but it needs some advise.
      Cant properly generate  and  tags getting multiple values in one line.(subTable should be a new th tag. an example of result that i am trying to achieve
  Thank you for advise</p>
  
  <p><strong>FICO SCORE</strong></p>
  
  <p>all        ≥ 760   0.50%   0.375%   0.25% 0%    -0.25% <br/>
  products    740     -759    0.375%   0.125% 0%   -0.375% -0.625%<br/>
              720     - 739   0.25%   -0.125%      -0.375% -0.625% -1.00%<br/>
              700     - 719   0.125%  -0.375%      -0.625% Not Eligible<br/></p>
  
  <p>Where they should be multiple.
      Please see my code below
      Thank you for any advise</p>
  
  <pre><code>    `var updated = jQuery.parseJSON(localStorage.getItem("tableJson"));
  
  
      function loop(obj, ul) {
          $.each(obj, function(key, val) {
              if(val &amp;&amp; typeof val === "object") { // object, call recursively
                  var ul2 = $("&lt;td&gt;").appendTo(
                      $("&lt;tr&gt;").appendTo(ul)
                  );
  
                  loop(val, ul2);
              } else {
                  $("&lt;td style='background-color: orange; color: white;;'&gt;", {
                      id: key
                  }).text(val).appendTo(ul);
              }
          });
      }
  
  
             var table = $("&lt;table&gt;");
  
             loop(updated, table);
  
          table.addClass("table").appendTo('#data');
  
  
              } else {
                  $("&lt;td style='background-color: orange; color: white;'&gt;", {
                      id: key
                    }).text(val).appendTo(ul);
                  }
              });
           }
  
  
             var table = $("&lt;table&gt;");
  
             loop(updated, table);
  
            table.addClass("table").appendTo('#data');
  
   `
                {
    "table": [
      {
        "subTable": [
          {
            "line": [
              "Fees"
  
            ]
          },
          {
            "line": [
              "Lender Fee",
              "$895"
            ]
          },
          {
            "line": [
              "Tax Service Fee",
              "$69"
            ]
          },
          {
            "line": [
              "Flood Certification Fee",
              "$12"
            ]
          },
          {
            "line": [
              "Texas Doc Prep Fee",
              "$150"
            ]
          }
        ]
      },
      {
        "subTable": [
          {
            "line": [
              "Max of LTV/CLTV/HCLTV Ratio"
  
            ]
          },
          {
            "line": [
              "≤ 60",
              "60.01-65",
              "65.01-70",
              "70.01-75",
              "75.01-80"
            ]
          }
        ]
      },
      {
        "subTable": [
          {
            "line": [
              "FICO Score"
  
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "≥ 760",
              "0.50%",
              "0.375%",
              "0.25%",
              "0%",
              "-0.25%"
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "740 - 759",
              "0.375%",
              "0.125%",
              "0%",
              "-0.375%",
              "-0.625%"
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "720 - 739",
              "0.25%",
              "-0.125%",
              "-0.375%",
              "-0.625%",
              "-1.00%"
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "700 - 719",
              "0.125%",
              "-0.375%",
              "-0.625%",
              "Not Eligible",
              "Not Eligible"
            ]
          }
        ]
      },
      {
        "subTable": [
          {
            "line": [
              "Loan Amount"
  
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "Up to $1M",
              "0.25%",
              "0.25%",
              "0.125%",
              "0%",
              "0%"
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "&gt;$1M Up to $1.5M",
              "0.25%",
              "0%",
              "-0.125%",
              "-0.25%",
              "-0.375%"
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "&gt;$1.5M Up to $2M",
              "0.125%",
              "0%",
              "-0.25%",
              "-0.375%",
              "Not Elig."
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "&gt;$2M Up to $2.5M",
              "0%",
              "-0.125%",
              "Not Eligible",
              "Not Eligible",
              "Not Eligible"
            ]
          }
        ]
      },
      {
        "subTable": [
          {
            "line": [
              "Loan Purpose/Occupancy/Property Type"
  
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "Purchase",
              "0.25%",
              "0.25%",
              "0.25%",
              "0.25%",
              "0.250%"
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "Cash-Out Refinance",
              "-0.250%",
              "-0.250%",
              "-0.250%",
              "Not Eligible",
              "Not Eligible"
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "Second Home",
              "-0.125%",
              "-0.25%",
              "-0.375%",
              "-0.75%",
              "Not Elig."
            ]
          },
          {
            "line": [
              "All Eligible Products",
              "2 Units",
              "-0.25%",
              "-0.25%",
              "Not Eligible",
              "Not Eligible",
              "Not Eligible"
            ]
          }
        ]
      },
      {
        "subTable": [
          {
            "line": [
              "Miscellaneous"
  
            ]
          },
          {
            "line": [
              "BE DTI &gt; 40%",
              "BE DTI &gt; 40%",
              "-0.625%",
              "-0.625%",
              "-0.625%",
              "-0.625%",
              "-0.625%"
            ]
          },
          {
            "line": [
              "Partial/No Impounds",
              "All States",
              "-0.15%",
              "-0.15%",
              "-0.15%",
              "-0.15%",
              "-0.15%"
            ]
          },
          {
            "line": [
              "Subordinate Financing",
              "Subordinate Financing",
              "-0.25%",
              "-0.25%",
              "-0.25%",
              "-0.25%",
              "-0.25%"
            ]
          }
        ]
      },
      {
        "subTable": [
          {
            "line": [
              "Eligible Broker Incentives"
  
            ]
          },
          {
            "line": [
              "Tier",
              "Super Elite",
              "Elite",
              "Gold",
              "Silver",
              "Bronze"
            ]
          },
          {
            "line": [
              "Elite Bonus",
              "0.250%",
              "0.125%",
              "0%",
              "0%",
              "0%"
            ]
          },
          {
            "line": [
              "Ethos Edge*",
              "0.125%",
              "0.125%",
              "0.125%",
              "0%",
              "0%"
            ]
          },
          {
            "line": [
              "Purchase Special (Purchase Primary Residence)",
              "0.125%",
              "0.125%",
              "0.125%",
              "0.125%",
              "0%"
            ]
          }
        ]
      },
      {
        "subTable": [
          {
            "line": [
              "Max Price (Including All Adjustments)"
  
            ]
          },
          {
            "line": [
              "Loan Amount",
              "≤ $1M",
              "&gt;$1M"
            ]
          },
          {
            "line": [
              "Fixed 30-Year",
              "102.00",
              "101.50"
            ]
          },
          {
            "line": [
              "Fixed 15-Year",
              "101.50",
              "101.25"
            ]
          },
          {
            "line": [
              "5/1 ARM",
              "100.85",
              "100.75"
            ]
          },
          {
            "line": [
              "7/1 ARM",
              "100.85",
              "100.75"
            ]
          }
        ]
      }
    ]
  }
  </code></pre>