使用tidyjson格式化JSON数据

时间:2016-01-31 22:10:54

标签: json r

我很想使用tidyjson软件包,因为它似乎有非常明确的说明如何使用它。

但是,我遇到了一些问题。如果这些是用户问题或其他原因,请帮助检查并告诉我。

  1. 我正在使用从http://jsonstudio.com/resources/

    下载的world_bank.json数据

    worldbank< - fromJSON(file =“world_bank.json”)

  2. 我确实在Rstudio中看到了50个列表。但是,当我尝试使用read_json时,我得到以下错误。

    > read_json(worldbank, format = "json")
    Error in file.info(path) : invalid filename argument
    
    
    > worldbank[[1]] %>% prettify
    Error: parse error: trailing garbage
                                         52b213b38594d8a2be17c780
                         (right here) ------^
    

1 个答案:

答案 0 :(得分:0)

使用jsonlite::stream_in作为lizzy建议使用stream unzip:

> download.file("http://jsonstudio.com/wp-content/uploads/2014/02/world_bank.zip", "world_bank.zip")
> world_bank <- jsonlite::stream_in(unz("world_bank.zip", "world_bank.json"))
> names(world_bank)
 [1] "_id"                      "approvalfy"               "board_approval_month"    
 [4] "boardapprovaldate"        "borrower"                 "closingdate"             
 [7] "country_namecode"         "countrycode"              "countryname"             
[10] "countryshortname"         "docty"                    "envassesmentcategorycode"
[13] "grantamt"                 "ibrdcommamt"              "id"                      
[16] "idacommamt"               "impagency"                "lendinginstr"            
[19] "lendinginstrtype"         "lendprojectcost"          "majorsector_percent"     
[22] "mjsector_namecode"        "mjtheme"                  "mjtheme_namecode"        
[25] "mjthemecode"              "prodline"                 "prodlinetext"            
[28] "productlinetype"          "project_abstract"         "project_name"            
[31] "projectdocs"              "projectfinancialtype"     "projectstatusdisplay"    
[34] "regionname"               "sector"                   "sector1"                 
[37] "sector2"                  "sector3"                  "sector4"                 
[40] "sector_namecode"          "sectorcode"               "source"                  
[43] "status"                   "supplementprojectflg"     "theme1"                  
[46] "theme_namecode"           "themecode"                "totalamt"                
[49] "totalcommamt"             "url"                     
相关问题