title: Extract tidy data from complex nested JSON in R
body: <p>Extracting tidy data from a simple JSON is trivial with the <code>tidyjson</code> package (<a href="https://cran.r-project.org/web/packages/tidyjson/vignettes/introduction-to-tidyjson.html" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/tidyjson/vignettes/introduction-to-tidyjson.html</a>)</p>
  
  <p>I haven't been able to apply this logic to a complex nested JSON structure. Similar question such as this one (<a href="https://stackoverflow.com/questions/36629362/how-do-you-extract-data-from-nested-json-data-in-r">how do you extract data from nested json data in R</a>) are too specific so I can't extrapolate it to other cases.</p>
  
  <p>A more general case could be given by this structure (see working reproducible examples here: 1.4 Example requests: <a href="https://www.ree.es/en/apidatos" rel="nofollow noreferrer">https://www.ree.es/en/apidatos</a>)</p>
  
  <pre><code>{
          "data": {
            "type": "WIDGET TYPE",
            "id": "WIDGET_ID",
            "attributes": {
              "title": "WIDGET NAME",
              "last-update": "2019-02-01T08:26:34.000+01:00",
              "description": "WIDGET DESCRIPTION",
            },
            "meta": {
              "cache-control": {
                "cache": "HIT",
                "expireAt": "2019-03-01T17:18:22"
              }
            }
          },
          "included": [
            {
              "type": "INDICATOR_1 TYPE",
              "id": "INDICADOR_1_ID",
              "groupId": null,
              "attributes": {
                "title": "INDICADOR_1 NAME",
                "description": "INDICADOR_1 DESCRIPTION",
                "color": "#2fa688",
                "type": "INDICADOR_1 TYPE",
                "magnitude": "INDICADOR_1 MAGNITUDE",
                "composite": false,
                "last-update": "2019-02-19T08:26:34.000+01:00",
                "values": [
                  {
                    "value": 12345,
                    "percentage": "VALUE BETWEEN 0 AND 1",
                    "datetime": "2019-02-04T20:44:00.000+01:00"
                  }
                ]
              },
             {
              "type": "INDICATOR_2 TYPE",
              "id": "INDICADOR_1_ID",
              "groupId": null,
              "attributes": {
                 …
              }
            }
          ]
         }
        }
  </code></pre>
  
  <ol>
  <li><p>The first level has an object <code>"data"</code> and an array <code>"included"</code></p></li>
  <li><p>The <code>"included"</code> array has one object for each indicator</p></li>
  <li><p>In each of these objects there is an <code>"attributes"</code> object with a <code>"values"</code> array where the final data are located: <code>"value"</code>, <code>"percentage"</code> and <code>"datetime"</code></p></li>
  </ol>
  
  <p>The goal would be to extract the data to a tidy dataframe with the columns <code>"type"</code>, <code>"title"</code>, <code>"value"</code>, <code>"percentage"</code> and <code>"datetime"</code></p>