title: Parsing a nested Json file in R
body: <p>I need to open and parse the following nested JSON file in R</p>
  
  <pre><code>[
  {
    "complemento": {
      "valorTotal": 24.9
    },
    "dets": [
      {
        "nItem": "1",
        "prod": {
          "indTot": "1",
          "qCom": 1.0,
          "uCom": "UN",
          "vProd": 3.5,
          "vUnCom": 3.5,
          "xProd": "AGUA"
        }
      },
      {
        "nItem": "2",
        "prod": {
          "indTot": "1",
          "qCom": 0.312,
          "uCom": "KG",
          "vProd": 21.4,
          "vUnCom": 68.6,
          "xProd": "BUFFET"
        }
      }
    ],
    "emit": {
      "cnpj": "01.234.567/0001-89",
      "enderEmit": {
        "fone": "1-650-933-4902",
        "xBairro": "",
        "xLgr": "650 Castro St. unit 210",
        "xMun": "Mountain View",
        "xPais": "United States",
        "uf": "CA"
      },
      "xFant": "TOTVS Labs"
    },
    "ide": {
      "dhEmi": {
        "$date": "2016-01-05T12:01:54.000Z"
      },
      "natOp": "VENDA"
    },
    "infAdic": {
      "infCpl": "Mesa 2"
    },
    "total": {
      "icmsTot": {
        "vDesc": 0.0,
        "vFrete": 0.0,
        "vOutro": 0.0,
        "vProd": 24.9,
        "vSeg": 0.0,
        "vTotTrib": 2.53,
        "vbc": 0.0,
        "vbcst": 0.0,
        "vcofins": 0.0,
        "vicms": 0.0,
        "vicmsDeson": 0.0,
        "vii": 0.0,
        "vipi": 0.0,
        "vnf": 24.9,
        "vpis": 0.0,
        "vst": 0.0
      }
    },
    "versaoDocumento": 1.0
  }
  ,{
    "complemento": {
      "valorTotal": 92.53
    },
    "dets": [
      {
        "nItem": "1",
        "prod": {
          "indTot": "1",
          "qCom": 1.218,
          "uCom": "KG",
          "vProd": 83.55,
          "vUnCom": 68.6,
          "xProd": "BUFFET"
        }
      },
      {
        "nItem": "2",
        "prod": {
          "indTot": "1",
          "qCom": 2.0,
          "uCom": "UN",
          "vProd": 9.0,
          "vUnCom": 4.5,
          "xProd": "REFRIGERANTE"
        }
      }
    ],
  </code></pre>
  
  <p>I can open it by using the <code>fromJSON</code> command</p>
  
  <pre><code>Data &lt;- fromJSON("sample.txt")
  </code></pre>
  
  <p>However, the <code>dets</code> column after opening it is a list and I cannot unlist it properly because the items are different.</p>
  
  <p><a href="https://i.stack.imgur.com/PZZwU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PZZwU.png" alt="enter image description here"></a></p>
  
  <pre><code>json.matchData &lt;- fromJSON("sample.txt")
  head(json.matchData)
  matchData.i &lt;- lapply(json.matchData$dets, function(x){unlist(x)})
  matchData &lt;- rbind.fill(lapply(matchData.i,
                             function(x) do.call("data.frame", as.list(x))
                             ))
  matchData &lt;- do.call("rbind", matchData.i)
  matchData &lt;- as.data.frame(matchData)
  </code></pre>
  
  <p>That is the result of the unlisted <code>dets</code> column. I am wondering if I could extract the values <code>nItem</code>, <code>vProd</code> and <code>xProd</code> from the loaded data.</p>
  
  <p><a href="https://i.stack.imgur.com/8kiEp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8kiEp.png" alt="enter image description here"></a></p>