title: Unnest/Unlist column with variable lengths in R
body: <p>I'm trying to wrangle a json file into a data frame but I'm having trouble when unnesting to a wider format because the columns contain lists of unequal sizes. In addition, it appears that one column of lists contains what should be the name of the new column and the other column contains the data.</p>
  <p>I apologize for not including a repex but I don't know how to create a data frame with lists. I've included a screen shot to hopefully highlight the issue.</p>
  <p><a href="https://i.stack.imgur.com/lmwIe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lmwIe.png" alt="nested data frame" /></a></p>
  <p>When I attempt to unnest with <code>raw_json2 %&gt;% unnest_wider(value)</code> I get the following error:
  <code>Error: Can't combine `..1$...1` &lt;character&gt; and `..27$...1` &lt;list&gt;.</code></p>
  <p>It appears that the column <code>type</code> contains what should be the column names, and that 'value' contains the values for those columns. So essentially columns would be added to my data frame from <code>type</code> and data added from <code>value</code>.</p>
  <p>EDIT------------------------------
  Sample data. I put the first 30 as there some tricky lists at the end.</p>
  <pre><code>&gt; dput(head(raw_json2, n=30))
  
  structure(list(id = c(112357710L, 112357713L, 112357714L, 112357717L, 
  112357719L, 112357723L, 112357727L, 112357730L, 112357732L, 112357736L, 
  112357737L, 112357738L, 112357744L, 112357745L, 112357746L, 112357747L, 
  112357759L, 112357760L, 112357761L, 112357764L, 112357765L, 112357766L, 
  112357767L, 112357775L, 112357777L, 112357780L, 112357782L, 112357783L, 
  112357784L, 112357791L), start_sec = c(&quot;00:00:19.000000&quot;, &quot;00:45:34.000000&quot;, 
  &quot;00:02:19.000000&quot;, &quot;00:00:49.000000&quot;, &quot;00:00:46.000000&quot;, &quot;00:00:59.000000&quot;, 
  &quot;00:01:17.000000&quot;, &quot;00:01:29.000000&quot;, &quot;00:01:43.000000&quot;, &quot;00:02:02.000000&quot;, 
  &quot;00:02:04.000000&quot;, &quot;00:02:06.000000&quot;, &quot;00:02:14.000000&quot;, &quot;00:02:36.000000&quot;, 
  &quot;00:02:22.000000&quot;, &quot;00:02:46.000000&quot;, &quot;00:02:52.000000&quot;, &quot;00:02:48.000000&quot;, 
  &quot;00:03:00.000000&quot;, &quot;00:03:02.000000&quot;, &quot;00:03:10.000000&quot;, &quot;00:03:12.000000&quot;, 
  &quot;00:04:01.000000&quot;, &quot;00:03:27.000000&quot;, &quot;00:04:15.000000&quot;, &quot;00:03:53.000000&quot;, 
  &quot;00:04:00.000000&quot;, &quot;00:04:03.000000&quot;, &quot;00:05:05.000000&quot;, &quot;00:05:06.000000&quot;
  ), end_sec = c(&quot;00:00:19.000000&quot;, &quot;00:45:34.000000&quot;, &quot;00:02:19.000000&quot;, 
  &quot;00:00:49.000000&quot;, &quot;00:00:46.000000&quot;, &quot;00:00:59.000000&quot;, &quot;00:01:17.000000&quot;, 
  &quot;00:01:29.000000&quot;, &quot;00:01:43.000000&quot;, &quot;00:02:02.000000&quot;, &quot;00:02:04.000000&quot;, 
  &quot;00:02:06.000000&quot;, &quot;00:02:14.000000&quot;, &quot;00:02:36.000000&quot;, &quot;00:02:22.000000&quot;, 
  &quot;00:02:46.000000&quot;, &quot;00:02:52.000000&quot;, &quot;00:02:48.000000&quot;, &quot;00:03:00.000000&quot;, 
  &quot;00:03:02.000000&quot;, &quot;00:03:10.000000&quot;, &quot;00:03:12.000000&quot;, &quot;00:04:01.000000&quot;, 
  &quot;00:03:27.000000&quot;, &quot;00:04:15.000000&quot;, &quot;00:03:53.000000&quot;, &quot;00:04:00.000000&quot;, 
  &quot;00:04:03.000000&quot;, &quot;00:05:05.000000&quot;, &quot;00:05:06.000000&quot;), type = list(
      c(&quot;teamNames&quot;, &quot;list&quot;), &quot;list&quot;, &quot;teamNames&quot;, &quot;teamNames&quot;, 
      c(&quot;teamNames&quot;, &quot;list&quot;), &quot;teamNames&quot;, &quot;teamNames&quot;, &quot;teamNames&quot;, 
      &quot;teamNames&quot;, c(&quot;teamNames&quot;, &quot;list&quot;), &quot;teamNames&quot;, &quot;teamNames&quot;, 
      &quot;teamNames&quot;, &quot;teamNames&quot;, &quot;teamNames&quot;, &quot;teamNames&quot;, &quot;teamNames&quot;, 
      &quot;teamNames&quot;, &quot;teamNames&quot;, &quot;teamNames&quot;, &quot;teamNames&quot;, &quot;teamNames&quot;, 
      &quot;teamNames&quot;, c(&quot;teamNames&quot;, &quot;list&quot;), &quot;teamNames&quot;, c(&quot;teamNames&quot;, 
      &quot;list&quot;), c(&quot;teamNames&quot;, &quot;list&quot;, &quot;chartPoint&quot;, &quot;chartPoint&quot;
      ), &quot;teamNames&quot;, &quot;teamNames&quot;, &quot;teamNames&quot;), value = list(c(&quot;Real Madrid&quot;, 
  &quot;kickoff&quot;), &quot;1&quot;, &quot;Real Madrid&quot;, &quot;Real Madrid&quot;, c(&quot;Real Madrid&quot;, 
  &quot;throw in&quot;), &quot;Real Madrid&quot;, &quot;Barcelona&quot;, &quot;Real Madrid&quot;, &quot;Barcelona&quot;, 
      c(&quot;Real Madrid&quot;, &quot;free kick&quot;), &quot;Real Madrid&quot;, &quot;Real Madrid&quot;, 
      &quot;Real Madrid&quot;, &quot;Real Madrid&quot;, &quot;Barcelona&quot;, &quot;Barcelona&quot;, &quot;Barcelona&quot;, 
      &quot;Real Madrid&quot;, &quot;Real Madrid&quot;, &quot;Barcelona&quot;, &quot;Barcelona&quot;, &quot;Real Madrid&quot;, 
      &quot;Real Madrid&quot;, c(&quot;Real Madrid&quot;, &quot;throw in&quot;), &quot;Real Madrid&quot;, 
      c(&quot;Real Madrid&quot;, &quot;corner kick&quot;), list(&quot;Real Madrid&quot;, &quot;save&quot;, 
          list(x = 483.51837158203, y = 397.89303588867, x2 = 0L, 
              y2 = 0L, type = &quot;point&quot;, sector = 1L, orientation = &quot;left&quot;), 
          list(x = 274.94967651367, y = 404.6828918457, x2 = 0L, 
              y2 = 0L, type = &quot;point&quot;, sector = 3L, orientation = &quot;left&quot;)), 
      &quot;Barcelona&quot;, &quot;Barcelona&quot;, &quot;Barcelona&quot;)), row.names = c(NA, 
  -30L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;))
  </code></pre>