jq: parse json

Description Usage Arguments Examples

Description

parse json

Usage

1
jq(json, ...)

Arguments

json

(character) Input json string

...

Addtn inputs to fromJSON

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
library("httr")
library("data.table")

# GBIF example
json <- content(GET('http://api.gbif.org/v0.9/occurrence/search?taxonKey=3119195'), as = "text")
json %>%
   jq %s%
   'results' %v%
   c('scientificName','country') %>%
   rbindlist

# PLOS example
## The jqr way
json <- content(GET('http://api.plos.org/search/?q=*:*&wt=json'), as = "text")
json %>%
   jq %s%
   'response.docs' %v%
   c('id','journal') %>%
   rbindlist
## How it would be otherwise
library("jsonlite")
res <- fromJSON(json, FALSE)
out <- res$response$docs
out2 <- lapply(out, function(x) x[c('id','journal')])
rbindlist(out2)
## Thought the jqr way is a tiny bit longer, it's much more intuitive

sckott/jqr documentation built on May 29, 2019, 4:02 p.m.