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

How to get a struct from ld-json #29

Open
lpvm opened this issue Apr 1, 2020 · 4 comments
Open

How to get a struct from ld-json #29

lpvm opened this issue Apr 1, 2020 · 4 comments

Comments

@lpvm
Copy link

lpvm commented Apr 1, 2020

For a document like:

   "@context": "https://schema.org/",
    "@type": "JobPosting",
    "title": "Gest",
    "employmentType": ["FULL_TIME","PART_TIME","CONTRACTOR","TEMPORARY","INTERN","VOLUNTEER","PER_DIEM","OTHER"],
    "baseSalary": "",
    "hiringOrganization": {
        "@type": "Organization",
        "name": "Debtges",
        "sameAs": "https://some.htm",
        "logo": "https://thumbs.some"
    }

How to get a struct like:

type job struct {
    title string
    employmentType []string
    baseSalary string
}
var j1 := job{
    title: "Gest",
    employmentType:     []string{"FULL_TIME","PART_TIME","CONTRACTOR","TEMPORARY","INTERN","VOLUNTEER","PER_DIEM","OTHER"},
    baseSalary: "", 
...
}
@dharmjit
Copy link

Is this supported? Or there different ways to handle it in application.

@kazarena
Copy link
Member

@dharmjit it depends on your use case and how you are using JSON-LD. As you may see from JsonLdProcessor interface, different JSON-LD operations return either map[string]interface{} or []interface{} or interface{}. After that, JSON-LD is just JSON. The easiest way to transform it into a specific structure is to perform a Marchall/Unmarshall operation with the JSON marshaller of your choice. Unfortunately, streaming JSON-LD is complicated and, currently, we don't support it.

@jaydonnell
Copy link

Is there an example somewhere that shows how to take a string that represents json-ld and gets it into a form that can be used by this library?

@kazarena
Copy link
Member

kazarena commented Nov 1, 2020

@jaydonnell if you marshal your JSON string into interface{}, the library will be able to process it.

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

No branches or pull requests

4 participants