1

I'm trying to get the author names of this paper by using the CrossRef API with curl.

curl -LH "Accept: application/citeproc+json" http://dx.doi.org/10.3389/fpls.2011.00050 | jq .author

Of course I get a JSON as response, but rather need pure text for further bash processing:

[
  {
    "given": "Fabio",
    "family": "Facchinelli",
    "affiliation": []
  },
  {
    "given": "Andreas P. M.",
    "family": "Weber",
    "affiliation": []
  }
]

I thought of using jq, but couldn't figure out, how to just get:

"Fabio Facchinelli, Andreas P. M. Weber"

Do you know a solution (must not be jq)?

peak
  • 105,803
  • 17
  • 152
  • 177

3 Answers3

0

Here's one way to do that with jq:

... | jq '.author[] | .given + " " + .family' | jq -s 'join(", ")'

Outputs:

"Fabio Facchinelli, Andreas P. M. Weber"
janos
  • 120,954
  • 29
  • 226
  • 236
0

Can do it with a sed script:

$ cat json.sed
/"given":/{
    s/^.*"given"://
    s/[",]//g
    h
}
/"family":/{
    s/^.*"family"://
    s/[",]//g
    G
    s/\n/, /
    p
}

Then call it like this:

$ sed -n -f json.sed curl.json 
 Facchinelli,  Fabio
 Weber,  Andreas P. M.
Jack
  • 5,801
  • 1
  • 15
  • 20
0

The task can be accomplished with just one invocation of jq:

 ... | jq '.author | map(.given + " " + .family) | join(", ")'
peak
  • 105,803
  • 17
  • 152
  • 177