title: Nested for loop with JSON file
body: <p>I don't think this question has been asked before, I can't seem to find it.</p>
  
  <p>I have a nested JSON file that I want to extract certain values from. I toyed around with <code>sapply</code> and then finally settled on using a nested <code>for loop</code> sequence, see below:</p>
  
  <pre><code>for(Factor in fund$Factors)
  {
  
    print(Factor$Name)
  
    for(FactorGroup in Factor$FactorGroups)
    {
  
      print(FactorGroup$Name)
  
      for(Model in FactorGroup$Models)
      {
        print(Model$Name )
  
        for(Position in Model$Positions)
        {
  
            print(Position$Symbol)
            print(Position$Quantity)
            print(Position$Risk)
            print(Position$MaxRisk)
            print(Position$Daysleft)
  
        }
      }
    }
  }
  </code></pre>
  
  <p>Using this I can extract exactly what I need, but it does it on a line by line basis so the output looks like this:</p>
  
  <pre><code>[1] "factor 1"
  [1] "factor group 1"
  [1] "model"
  [1] "position 1"
  [1] 1
  [1] -769.1946
  [1] -7433.627
  [1] 14
  [1] "position 2"
  [1] 5
  [1] -3724.63
  [1] -12062.5
  [1] 76
  </code></pre>
  
  <p>This continues on for roughly 900 lines. What I'm wondering is if they're is a better way to organize this output. Ideally, I would like to concatenate each full sequence into a vector and then go to the next loop. For example, with this our output above would read something like:</p>
  
  <pre><code>[1] "factor 1" - "factor group 1" - "model" - "position 1" - 1 - -769.1946 - -7433.627 - 14
  [1] "factor 1" - "factor group 1" - "model" - "position 2" - 5 - -3724.63 - -12062.5 - 76
  </code></pre>
  
  <p>And this would iterate until it's looped through the entire file (e.g.,through factor 2, factor group, etc.)</p>
  
  <p>Thanks!</p>