Our Next Story

jq demo

What about adding more columns?

After much more experimentation and looking closely at the jq documentation you can build up a list of filters that can transform your data. I found it easer to break things up and pipe through different instances of jq.

    jq '.["orcid-profile"]["orcid-activities"]["orcid-works"]["orcid-work"][]' example.json |\
      jq '{workType: .["work-type"], journalTitle: .["journal-title"].value, id: .["work-external-identifiers"]["work-external-identifier"][]["work-external-identifier-id"].value, idType: .["work-external-identifiers"]["work-external-identifier"][]["work-external-identifier-type"]}' |\
        jq -r '. | [.workType, .journalTitle, .idType, .id] | join(",")' > example.csv

See example.csv

    JOURNAL_ARTICLE,,DOI,10.5062/F42R3PMS
    JOURNAL_ARTICLE,,EID,10.5062/F42R3PMS
    JOURNAL_ARTICLE,,DOI,2-s2.0-84858766300
    JOURNAL_ARTICLE,,EID,2-s2.0-84858766300
    JOURNAL_ARTICLE,Science & Technology Libraries,DOI,10.1080/0194262x.2015.1135304
    JOURNAL_ARTICLE,Abstracts of Papers of the American Chemical Society,ISSN,0065-7727
    OTHER,Chemical Information for Chemists,DOI,10.1039/9781782620655-00206
    OTHER,Chemical Information for Chemists,ISBN,10.1039/9781782620655-00206
    OTHER,Chemical Information for Chemists,DOI,978-1-84973-551-3
    OTHER,Chemical Information for Chemists,ISBN,978-1-84973-551-3
    JOURNAL_ARTICLE,,DOI,10.5062/F42R3PMS
    JOURNAL_ARTICLE,,EID,10.5062/F42R3PMS
    JOURNAL_ARTICLE,,DOI,2-s2.0-84858766300
    JOURNAL_ARTICLE,,EID,2-s2.0-84858766300
    JOURNAL_ARTICLE,Abstracts of Papers of the American Chemical Society,ISSN,0065-7727
    JOURNAL_ARTICLE,Abstracts of Papers of the American Chemical Society,ISSN,0065-7727
    JOURNAL_ARTICLE,Abstracts of Papers of the American Chemical Society,ISSN,0065-7727
    JOURNAL_ARTICLE,Abstracts of Papers of the American Chemical Society,ISSN,0065-7727
    JOURNAL_ARTICLE,Abstracts of Papers of the American Chemical Society,ISSN,0065-7727
    JOURNAL_ARTICLE,Abstracts of Papers of the American Chemical Society,ISSN,0065-7727
    JOURNAL_ARTICLE,Abstracts of Papers of the American Chemical Society,ISSN,0065-7727
    CONFERENCE_PAPER,,EID,2-s2.0-2442514124

This is OK but sometimes it is easier todo this type of transformation in tools like OpenRefine.