Files
fil/docs/snippets/r/plugins/plugin_extractor.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

26 lines
644 B
Markdown

<!-- snippet:syntax-only -->
```r title="R"
library(kreuzberg)
custom_json_extractor <- function(path, mime_type) {
raw <- readLines(path, warn = FALSE)
parsed <- jsonlite::fromJSON(paste(raw, collapse = "\n"))
text <- paste(unlist(parsed), collapse = "\n")
return(list(
content = text,
mime_type = "application/json",
pages = 1L,
metadata = list(extractor = "custom-json-extractor")
))
}
register_document_extractor("custom-json-extractor", custom_json_extractor)
result <- extract_file_sync("data.json", "application/json", NULL)
cat(sprintf("Extracted %d characters from JSON\n", nchar(result$content)))
```