Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Dereferencing a URL did not result in a valid JSON-LD context" for all given examples #37

Closed
lanfeust21 opened this issue Aug 17, 2020 · 4 comments · Fixed by #38
Closed

Comments

@lanfeust21
Copy link

package main

import (
	"github.com/piprate/json-gold/ld"
	"log"
)

func main() {
	proc := ld.NewJsonLdProcessor()
	options := ld.NewJsonLdOptions("")

	// expanding remote document

	expanded, err := proc.Expand("http://json-ld.org/test-suite/tests/expand-0002-in.jsonld", options)
	if err != nil {
		log.Println("Error when expanding JSON-LD document:", err)
		return
	}

	ld.PrintDocument("JSON-LD expansion succeeded", expanded)

	// expanding in-memory document

	doc := map[string]interface{}{
		"@context":  "https://schema.org/Person",
		"@type":     "Person",
		"name":      "Jane Doe",
		"jobTitle":  "Professor",
		"telephone": "(425) 123-4567",
		"url":       "http://www.janedoe.com",
	}

	expanded, err = proc.Expand(doc, options)
	if err != nil {
		panic(err)
	}

	ld.PrintDocument("JSON-LD expansion succeeded", expanded)
}

panic: loading remote context failed: Dereferencing a URL did not result in a valid JSON-LD context: https://schema.org/Person

goroutine 1 [running]:
main.main()
/Users/denislamotte/Desktop/work/jsonld/jsonld.go:35 +0x578
exit status 2

@lanfeust21 lanfeust21 changed the title "Dereferencing a URL did not result in a valid JSON-LD context" for all example given "Dereferencing a URL did not result in a valid JSON-LD context" for all given examples Aug 17, 2020
@kazarena
Copy link
Member

@lanfeust21, either "http://schema.org" or "https://schema.org" are correct contexts for schema.org. "https://schema.org/Person" is not (it's a type). Please refer to schema.org for valid examples of JSON-LD for Person.

@lanfeust21
Copy link
Author

lanfeust21 commented Aug 17, 2020

Maybe but it's the example given by the code i did not change anything.
The change proposed, did not change anything and still create the same error

@kazarena
Copy link
Member

@lanfeust21 can you please provide a link to the example that uses

"@context":  "https://schema.org/Person",

?

You reported that the proposed changes don't work either. I think I found the underlying reason. See
schemaorg/schemaorg#2578 (comment) for more information. schema.org's content negotiation has changed in May 2020. Since then, multiple fixes were proposed by various JSON-LD implementations, including RDFLib/rdflib#1125 and lanthaler/JsonLD@f8dff42.

Back to the issue, https://schema.org now returns the following Link in the header:

link: </docs/jsonldcontext.jsonld>; rel="alternate"; type="application/ld+json"

Currently, this library only supports rel="http://www.w3.org/ns/json-ld#context" as per JSON-LD 1.1 spec.

Proposed solution

If you use the actual location of schema.org context:

"@context":  "https://schema.org/docs/jsonldcontext.jsonld",

The example should work. Please note that it is considered the best practice to cache context documents in production applications.

We will add support for rel="alternate" in the next release. I can't provide ETA just yet.

Thanks for reporting.

@kazarena
Copy link
Member

The fix is in the master. It will be included in the next minor release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants