Closed oggioniale closed 12 months ago
solved with this query:
publication_state: .metadata.publication_state,
type: .metadata | [if (has("resource_types")) then .resource_types[].resource_type_general else "no_resource_types_declared" end][]
so the full example for JSON without type is:
y <- 'https://b2share.eudat.eu/api/records/a572efec373446169949f7769f829fc4'
jqr::jq(
url(y),
as.character(
"{
publication_state: .metadata.publication_state,
type: .metadata | [if (has("resource_types")) then .resource_types[].resource_type_general else "no_resource_types_declared" end][]
}"
)
)
[
"publication_state": "published",
"type": "no_resource_types_declared"
]
I would like to get a result even if the field is missing. In this example
x
contains theresource_type
field, in the case ofy
the field is missing. How do I make a query that is valid in both cases and returns both publication_state and type?