The structured data pages embed as JSON-LD: the text of each
<script type="application/ld+json"> below the given nodes (and the
nodes themselves), in document order. The type is matched as a MIME
type: case-insensitively, ignoring surrounding whitespace and any
parameters.
Arguments
- x
A
zuhtml_documentorzuhtml_nodeset.- parse
If
TRUE, parse each block withjsonlite::fromJSON()(withsimplifyVector = FALSE, so objects are named lists and arrays are lists). This needs the jsonlite package. A wrapper around the whole block,<![CDATA[ ... ]]>or<!-- ... -->, optionally commented out with//or/* */as pages often do, is removed first.
Value
With parse = FALSE, a character vector: the text of each
block, exactly as written. With parse = TRUE, a list as long as that
vector: each block's parsed value, or NULL for a block that is not
valid JSON; the texts are kept in its attribute "json".
See also
Other metadata:
html_meta(),
html_microdata(),
html_title()
Examples
doc <- html_parse(paste0(
"<script type='application/ld+json'>",
'{"@context": "https://schema.org", "@type": "Person", "name": "Ada"}',
"</script>"
))
html_json_ld(doc)
#> [1] "{\"@context\": \"https://schema.org\", \"@type\": \"Person\", \"name\": \"Ada\"}"
if (requireNamespace("jsonlite", quietly = TRUE)) {
html_json_ld(doc, parse = TRUE)[[1]]$name
}
#> [1] "Ada"