colearendt / tidyjson

Tidy your JSON data in R with tidyjson
Other
182 stars 14 forks source link

..JSON column without selecting it #136

Closed ssh352 closed 3 years ago

ssh352 commented 3 years ago

Hi, very nice package, could anyone advise how to remove ..JSON column, I didn't select it.

![Uploading Screen Shot 2021-07-14 at 3.21.58 PM.png…]()

colearendt commented 3 years ago

Hello! It would be helpful if you could share a reprex, so it is easier to understand what you are trying to accomplish!

In any case, the ..JSON column disappears when you tell tidyjson "Ok, I'm done with the JSON." The easiest way to do that is as_tibble(). This moves you fully into the realm of dplyr, tidyr, etc. and drops the tbl_json class:

library(tidyjson)
#> 
#> Attaching package: 'tidyjson'
#> The following object is masked from 'package:stats':
#> 
#>     filter
tmp <- as_tbl_json('{"one": "two", "three": "four"}')
(make_it <- tmp %>% gather_object() %>% append_values_string())
#> # A tbl_json: 2 x 4 tibble with a "JSON" attribute
#>   ..JSON     document.id name  string
#>   <chr>            <int> <chr> <chr> 
#> 1 "\"two\""            1 one   two   
#> 2 "\"four\""           1 three four

make_it %>% as_tibble()
#> # A tibble: 2 x 3
#>   document.id name  string
#>         <int> <chr> <chr> 
#> 1           1 one   two   
#> 2           1 three four

Created on 2021-07-14 by the reprex package (v0.3.0)

ssh352 commented 3 years ago

Thank you, it fixed my problem, somehow my screenshot didn't upload. And glad to learn reprex package.