json-gold icon indicating copy to clipboard operation
json-gold copied to clipboard

How to get a struct from ld-json

Open lpvm opened this issue 4 years ago • 4 comments

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: "", 
...
}

lpvm avatar Apr 01 '20 16:04 lpvm

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

dharmjit avatar Sep 18 '20 14:09 dharmjit

@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.

kazarena avatar Sep 18 '20 14:09 kazarena

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?

jaydonnell avatar Nov 01 '20 00:11 jaydonnell

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

kazarena avatar Nov 01 '20 11:11 kazarena