A golang command line utility and library to extract JSON-LD data embedded in HTML.
go get github.com/daetal-us/getld
Note: results are always returned as an array.
Retrieve JSON-LD data embedded in HTML from a remote source:
getld https://apple.com
Retrieve JSON-LD data embedded in HTML from multiple remote sources:
getld https://apple.com https://adobe.com
Note: results from multiple remote sources are combined into a single array.
package main
import (
"log"
"encoding/json"
"github.com/daetal-us/getld/extract"
)
func main() {
extractFromHTML()
extractFromURL()
}
func extractFromHTML() {
html := `<html><body><script type="application/json+ld>{"@type":"organization","name":"example"}</script></body></html>"`
results, err := extract.FromHTML(html)
if err != nil {
log.Fatal(err)
}
encoded, err := json.Marshal(results)
if err != nil {
log.fatal(err)
}
log.Println(string(encoded)) // [{"@type":"organization","name":"example"}]
}
func extractFromURL() {
results, err := extract.FromURL("https://apple.com")
if err != nil {
log.Fatal(err)
}
encoded, err := json.Marshal(results)
if err != nil {
log.fatal(err)
}
log.Println(string(encoded)) // [...]
}