r语言 - JQR包不匹配jq的结果


person <- GET(
"https://api.secure.com/v4/people/111322450?$expand=customFields",
accept_json(),
add_headers(Accept = 'application/json',
Authorization = APIKey)
)
capture <- content(person)
dput(capture)
capture <- list(vanId = 111322450L, firstName = "Joe", lastName = "Smith", 
middleName = NULL, suffix = NULL, title = "Mr.", contactMode = "Person", 
organizationContactCommonName = NULL, organizationContactOfficialName = NULL, 
salutation = "Joe", formalSalutation = "Mr. Smith", additionalSalutation = NULL, 
preferredPronoun = NULL, envelopeName = "Joe Smith", formalEnvelopeName = "Mr. Joe Smith", 
additionalEnvelopeName = NULL, contactMethodPreferenceCode = NULL, 
nickname = NULL, website = NULL, professionalSuffix = NULL, 
party = NULL, employer = NULL, occupation = NULL, sex = NULL, 
dateOfBirth = NULL, selfReportedRace = NULL, selfReportedEthnicity = NULL, 
selfReportedRaces = NULL, selfReportedEthnicities = NULL, 
selfReportedGenders = NULL, selfReportedSexualOrientations = NULL, 
selfReportedLanguagePreference = NULL, emails = NULL, phones = NULL, 
addresses = NULL, recordedAddresses = NULL, identifiers = NULL, 
codes = NULL, customFields = list(list(customField = list(
customFieldId = 54L, customFieldParentId = NULL, customFieldName = "If you're in college, which college?", 
customFieldGroupId = 12L, customFieldGroupName = "College", 
customFieldGroupType = "Contacts", customFieldTypeId = "T", 
isEditable = TRUE, maxTextboxCharacters = 75L, availableValues = NULL, 
isExportable = TRUE), customFieldId = 54L, customFieldGroupId = 12L, 
assignedValue = NULL), list(customField = list(customFieldId = 63L, 
customFieldParentId = NULL, customFieldName = "Graduation Year", 
customFieldGroupId = 12L, customFieldGroupName = "College", 
customFieldGroupType = "Contacts", customFieldTypeId = "S", 
isEditable = TRUE, maxTextboxCharacters = NULL, availableValues = list(
list(id = 1L, name = "2017", parentValueId = NULL), 
list(id = 2L, name = "2018", parentValueId = NULL), 
list(id = 3L, name = "2019", parentValueId = NULL), 
list(id = 4L, name = "2020", parentValueId = NULL), 
list(id = 5L, name = "2021", parentValueId = NULL), 
list(id = 6L, name = "2022", parentValueId = NULL), 
list(id = 7L, name = "2023", parentValueId = NULL), 
list(id = 8L, name = "2024", parentValueId = NULL), 
list(id = 11L, name = "2025", parentValueId = NULL), 
list(id = 12L, name = "2026", parentValueId = NULL), 
list(id = 9L, name = "Already graduated", parentValueId = NULL), 
list(id = 10L, name = "Not applicable", parentValueId = NULL)), 
isExportable = TRUE), customFieldId = 63L, customFieldGroupId = 12L, 
assignedValue = NULL), list(customField = list(customFieldId = 81L, 
customFieldParentId = NULL, customFieldName = "School Organization", 
customFieldGroupId = 12L, customFieldGroupName = "College", 
customFieldGroupType = "Contacts", customFieldTypeId = "S", 
isEditable = TRUE, maxTextboxCharacters = NULL, availableValues = list(
list(id = 1L, name = "Administration/Administrators", 
parentValueId = NULL), list(id = 2L, name = "Class Representatives", 
parentValueId = NULL), list(id = 3L, name = "Greek Life", 
parentValueId = NULL), list(id = 4L, name = "Other", 
parentValueId = NULL), list(id = 5L, name = "Student Clubs", 
parentValueId = NULL)), isExportable = TRUE), 
customFieldId = 81L, customFieldGroupId = 12L, assignedValue = NULL), 
list(customField = list(customFieldId = 82L, customFieldParentId = NULL, 
customFieldName = "School Organization Name", customFieldGroupId = 12L, 
customFieldGroupName = "College", customFieldGroupType = "Contacts", 
customFieldTypeId = "T", isEditable = TRUE, maxTextboxCharacters = 75L, 
availableValues = NULL, isExportable = TRUE), customFieldId = 82L, 
customFieldGroupId = 12L, assignedValue = NULL), 
list(customField = list(customFieldId = 83L, customFieldParentId = NULL, 
customFieldName = "Gender", customFieldGroupId = 36L, 
customFieldGroupName = "Demographics", customFieldGroupType = "Contacts", 
customFieldTypeId = "T", isEditable = TRUE, maxTextboxCharacters = 75L, 
availableValues = NULL, isExportable = TRUE), customFieldId = 83L, 
customFieldGroupId = 36L, assignedValue = "Male"), 
list(customField = list(customFieldId = 84L, customFieldParentId = NULL, 
customFieldName = "Race", customFieldGroupId = 36L, 
customFieldGroupName = "Demographics", customFieldGroupType = "Contacts", 
customFieldTypeId = "T", isEditable = TRUE, maxTextboxCharacters = 75L, 
availableValues = NULL, isExportable = TRUE), customFieldId = 84L, 
customFieldGroupId = 36L, assignedValue = "Caucasian"), 
list(customField = list(customFieldId = 85L, customFieldParentId = NULL, 
customFieldName = "Age", customFieldGroupId = 36L, 
customFieldGroupName = "Demographics", customFieldGroupType = "Contacts", 
customFieldTypeId = "T", isEditable = TRUE, maxTextboxCharacters = 75L, 
availableValues = NULL, isExportable = TRUE), customFieldId = 85L, 
customFieldGroupId = 36L, assignedValue = "31"), 
list(customField = list(customFieldId = 70L, customFieldParentId = NULL, 
customFieldName = "Are you over 21?", customFieldGroupId = 16L, 
customFieldGroupName = "RSVPs", customFieldGroupType = "Contacts", 
customFieldTypeId = "S", isEditable = TRUE, maxTextboxCharacters = NULL, 
availableValues = list(list(id = 1L, name = "no", 
parentValueId = NULL), list(id = 2L, name = "yes", 
parentValueId = NULL)), isExportable = TRUE), 
customFieldId = 70L, customFieldGroupId = 16L, assignedValue = NULL), 
list(customField = list(customFieldId = 12L, customFieldParentId = NULL, 
customFieldName = "Opt-in to SMS messages", customFieldGroupId = 9L, 
customFieldGroupName = "SMS OPT", customFieldGroupType = "Contacts", 
customFieldTypeId = "B", isEditable = TRUE, maxTextboxCharacters = NULL, 
availableValues = NULL, isExportable = FALSE), customFieldId = 12L, 
customFieldGroupId = 9L, assignedValue = NULL), list(
customField = list(customFieldId = 75L, customFieldParentId = NULL, 
customFieldName = "Instagram Handle", customFieldGroupId = 34L, 
customFieldGroupName = "Social Media", customFieldGroupType = "Contacts", 
customFieldTypeId = "T", isEditable = TRUE, maxTextboxCharacters = 75L, 
availableValues = NULL, isExportable = TRUE), 
customFieldId = 75L, customFieldGroupId = 34L, assignedValue = NULL), 
list(customField = list(customFieldId = 79L, customFieldParentId = NULL, 
customFieldName = "Facebook Username", customFieldGroupId = 34L, 
customFieldGroupName = "Social Media", customFieldGroupType = "Contacts", 
customFieldTypeId = "T", isEditable = TRUE, maxTextboxCharacters = 75L, 
availableValues = NULL, isExportable = TRUE), customFieldId = 79L, 
customFieldGroupId = 34L, assignedValue = NULL), 
list(customField = list(customFieldId = 66L, customFieldParentId = NULL, 
customFieldName = "Upload ", customFieldGroupId = 31L, 
customFieldGroupName = "Story Collection", customFieldGroupType = "Contacts", 
customFieldTypeId = "S", isEditable = TRUE, maxTextboxCharacters = NULL, 
availableValues = list(), isExportable = TRUE), customFieldId = 66L, 
customFieldGroupId = 31L, assignedValue = NULL), 
list(customField = list(customFieldId = 65L, customFieldParentId = NULL, 
customFieldName = "Story Collection ", customFieldGroupId = 31L, 
customFieldGroupName = "Story Collection", customFieldGroupType = "Contacts", 
customFieldTypeId = "B", isEditable = TRUE, maxTextboxCharacters = NULL, 
availableValues = NULL, isExportable = TRUE), customFieldId = 65L, 
customFieldGroupId = 31L, assignedValue = NULL), 
list(customField = list(customFieldId = 64L, customFieldParentId = NULL, 
customFieldName = "Story Upload", customFieldGroupId = 31L, 
customFieldGroupName = "Story Collection", customFieldGroupType = "Contacts", 
customFieldTypeId = "T", isEditable = TRUE, maxTextboxCharacters = 75L, 
availableValues = NULL, isExportable = TRUE), customFieldId = 64L, 
customFieldGroupId = 31L, assignedValue = NULL), 
list(customField = list(customFieldId = 13L, customFieldParentId = NULL, 
customFieldName = "I would like to volunteer.", customFieldGroupId = 10L, 
customFieldGroupName = "Volunteer", customFieldGroupType = "Contacts", 
customFieldTypeId = "B", isEditable = TRUE, maxTextboxCharacters = NULL, 
availableValues = NULL, isExportable = FALSE), customFieldId = 13L, 
customFieldGroupId = 10L, assignedValue = NULL), 
list(customField = list(customFieldId = 38L, customFieldParentId = NULL, 
customFieldName = "Text Opt-in (old)", customFieldGroupId = 10L, 
customFieldGroupName = "Volunteer", customFieldGroupType = "Contacts", 
customFieldTypeId = "B", isEditable = TRUE, maxTextboxCharacters = NULL, 
availableValues = NULL, isExportable = TRUE), customFieldId = 38L, 
customFieldGroupId = 10L, assignedValue = NULL), 
list(customField = list(customFieldId = 62L, customFieldParentId = NULL, 
customFieldName = "Are you a high school student?", 
customFieldGroupId = 10L, customFieldGroupName = "Volunteer", 
customFieldGroupType = "Contacts", customFieldTypeId = "B", 
isEditable = TRUE, maxTextboxCharacters = NULL, availableValues = NULL, 
isExportable = TRUE), customFieldId = 62L, customFieldGroupId = 10L, 
assignedValue = NULL), list(customField = list(customFieldId = 67L, 
customFieldParentId = NULL, customFieldName = "Have you done any sort of calling, texting, or door-knocking for a political or issue campaign?", 
customFieldGroupId = 10L, customFieldGroupName = "Volunteer", 
customFieldGroupType = "Contacts", customFieldTypeId = "S", 
isEditable = TRUE, maxTextboxCharacters = NULL, availableValues = list(
list(id = 1L, name = "No", parentValueId = NULL), 
list(id = 2L, name = "Yes", parentValueId = NULL)), 
isExportable = TRUE), customFieldId = 67L, customFieldGroupId = 10L, 
assignedValue = NULL), list(customField = list(customFieldId = 68L, 
customFieldParentId = NULL, customFieldName = "Check here if you are a Spanish speaker", 
customFieldGroupId = 10L, customFieldGroupName = "Volunteer", 
customFieldGroupType = "Contacts", customFieldTypeId = "B", 
isEditable = TRUE, maxTextboxCharacters = NULL, availableValues = NULL, 
isExportable = TRUE), customFieldId = 68L, customFieldGroupId = 10L, 
assignedValue = NULL), list(customField = list(customFieldId = 69L, 
customFieldParentId = NULL, customFieldName = "Best way to remind you of your shift?", 
customFieldGroupId = 10L, customFieldGroupName = "Volunteer", 
customFieldGroupType = "Contacts", customFieldTypeId = "S", 
isEditable = TRUE, maxTextboxCharacters = NULL, availableValues = list(
list(id = 1L, name = "Email", parentValueId = NULL), 
list(id = 2L, name = "Phone call", parentValueId = NULL), 
list(id = 3L, name = "Text", parentValueId = NULL)), 
isExportable = TRUE), customFieldId = 69L, customFieldGroupId = 10L, 
assignedValue = NULL), list(customField = list(customFieldId = 76L, 
customFieldParentId = NULL, customFieldName = "Vote Tripling Contact 1", 
customFieldGroupId = 35L, customFieldGroupName = "Vote Tripling", 
customFieldGroupType = "Contacts", customFieldTypeId = "T", 
isEditable = TRUE, maxTextboxCharacters = 75L, availableValues = NULL, 
isExportable = TRUE), customFieldId = 76L, customFieldGroupId = 35L, 
assignedValue = NULL), list(customField = list(customFieldId = 77L, 
customFieldParentId = NULL, customFieldName = "Vote Tripling Contact 2", 
customFieldGroupId = 35L, customFieldGroupName = "Vote Tripling", 
customFieldGroupType = "Contacts", customFieldTypeId = "T", 
isEditable = TRUE, maxTextboxCharacters = 75L, availableValues = NULL, 
isExportable = TRUE), customFieldId = 77L, customFieldGroupId = 35L, 
assignedValue = NULL), list(customField = list(customFieldId = 78L, 
customFieldParentId = NULL, customFieldName = "Vote Tripling Contact 3", 
customFieldGroupId = 35L, customFieldGroupName = "Vote Tripling", 
customFieldGroupType = "Contacts", customFieldTypeId = "T", 
isEditable = TRUE, maxTextboxCharacters = 75L, availableValues = NULL, 
isExportable = TRUE), customFieldId = 78L, customFieldGroupId = 35L, 
assignedValue = NULL), list(customField = list(customFieldId = 71L, 
customFieldParentId = NULL, customFieldName = "Yes, send me a text on election day to remind me to vote", 
customFieldGroupId = 32L, customFieldGroupName = "Voting", 
customFieldGroupType = "Contacts", customFieldTypeId = "B", 
isEditable = TRUE, maxTextboxCharacters = NULL, availableValues = NULL, 
isExportable = TRUE), customFieldId = 71L, customFieldGroupId = 32L, 
assignedValue = NULL), list(customField = list(customFieldId = 72L, 
customFieldParentId = NULL, customFieldName = "how do you plan on voting?", 
customFieldGroupId = 32L, customFieldGroupName = "Voting", 
customFieldGroupType = "Contacts", customFieldTypeId = "T", 
isEditable = TRUE, maxTextboxCharacters = 75L, availableValues = NULL, 
isExportable = TRUE), customFieldId = 72L, customFieldGroupId = 32L, 
assignedValue = NULL), list(customField = list(customFieldId = 80L, 
customFieldParentId = NULL, customFieldName = "I'm a first-time voter!", 
customFieldGroupId = 32L, customFieldGroupName = "Voting", 
customFieldGroupType = "Contacts", customFieldTypeId = "B", 
isEditable = TRUE, maxTextboxCharacters = NULL, availableValues = NULL, 
isExportable = TRUE), customFieldId = 80L, customFieldGroupId = 32L, 
assignedValue = NULL)), primaryCustomField = NULL, 
contributionSummary = NULL, suppressions = NULL, caseworkCases = NULL, 
caseworkIssues = NULL, caseworkStories = NULL, notes = NULL, 
scores = NULL, customProperties = NULL, electionRecords = NULL, 
membershipStatus = NULL, organizationRoles = NULL, districts = NULL, 
surveyQuestionResponses = NULL, finderNumber = NULL, biographyImageUrl = NULL, 
primaryContact = NULL)

首先将其转换为JSON:

capture_json <- rjson::toJSON(capture)

然后我把它缩小到只包括.customFields,然后我过滤了我想要的customFieldId:

capture_jq <- capture_json %>% jqr::jq('.customFields') %>% jq('.[] | select(.customField.customFieldId | IN(83,84,85))')

使用JSON数据,我试图提取assignedValue字段中列出的值。当我使用jq工具和.[]|.assignedValue过滤器时,它返回我想要的值:

"Male"
"Caucasian"
"31"

你可以在这个链接中看到。

在我的R脚本中,JSON数据存储在一个名为capture_jq的变量中,然后我运行这个脚本:

assigned_values <- capture_jq %>% jq('.[]|."assignedValue"') 

但是当我运行这个脚本时,它所做的就是返回空值,看起来像这样:

[
null,
null,
null
]

我做错了什么?为什么它在我上面提供的jqplay链接中工作良好,但在R中不使用jqr包?

我们可以更改语法,因为结构与在网站上运行的OP略有不同

> capture_jq %>% jq('."assignedValue"')
[
"Male",
"Caucasian",
"31"
]

相关内容

  • 没有找到相关文章

最新更新