json-gold
json-gold copied to clipboard
How to get a struct from ld-json
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: "",
...
}
Is this supported? Or there different ways to handle it in application.
@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.
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 if you marshal your JSON string into interface{}, the library will be able to process it.