Skip to content

Instantly share code, notes, and snippets.

View gu-stat's full-sized avatar

Gustavo gu-stat

View GitHub Profile
@gu-stat
gu-stat / Desc_JSON_to_df.md
Created July 22, 2017 22:30 — forked from gluc/Desc_JSON_to_df.md
Convert a complex JSON to an R data.frame

This gist shows how to convert a nested JSON file to an R data.frame. To do this, it uses jsonlite and data.tree.

The gist contains two examples: one is a bit simpler, the second one a bit more advanced.

Example 1

In the first example, we download all the repos from Hadley Wickham's Github account from https://api.github.com/users/hadley/repos . This JSON contains a nested owner object. The code shows how to convert that in a flat data.frame in three statements:

  1. line 5: download
  2. line 8: convert to data.tree