Flatten deep nested json in R
<p>I am trying to use R to convert a nested JSON file into a two dimensional dataframe. </p>

<p>My JSON file has a nested structure. But, the names and properties are the same across levels.</p>

<pre><code>{"name":"A", "value":"1", "c":
  [{"name":"a1", "value":"11", "c":
    [{"name":"a11", "value":"111"}, 
    {"name":"a12", "value":"112"}]
  }, 
  {"name":"a2", "value":"12"}]
}
</code></pre>

<p>The desired dataset would look like this.  Although the exact column names can be different.</p>

<pre><code>name    value   c__name c_value c_c_name    c_c_value
A       1       a1      11      a11         111
A       1       a1      11      a12         112
A       1       a2      12
</code></pre>

<p>The code I have so far flattens the data, but it only seems to work for the first level (see the screenshot of the output).  </p>

<pre><code>library(jsonlite)
json_file &lt;- '    {"name":"A", "value":"1", "c":
      [{"name":"a1", "value":"11", "c":
[{"name":"a11", "value":"111"}, 
{"name":"a12", "value":"112"}]
}, 
{"name":"a2", "value":"12"}]
}'

data &lt;- fromJSON(json_file, flatten = TRUE)
View(data)
</code></pre>

<p><img src="https://i.stack.imgur.com/vpf56.png" alt="enter image description here"></p>

<p>I tried multiple packages, including jsonlite and RJSONIO, I spent the last 5 hours 5 hours debugging this and trying various online tutorial, but without success.  Thanks for your help!</p>