I’m working on a Go project with multiple folders containing JSON files. Among these files, one serves as the entry point. My task is to unmarshal the JSON schema into a struct.
Dummy Folder Structure:
Project
Temp
Temp1
a.json
Temp2
b.json
main.go
a.json:
{
"leaveOrganizationRoom": {
"description": "User switches between organization or disconnects the application",
"publish": {
"$ref": "../temp2/b.json#/leaveOrganizationRoom"
}
}
}
b.json
{
"leaveOrganizationRoom": {
"summary": "Leave Organization Room"
}
}
In this scenario, “a.json” serves as the entry point, requiring unmarshalling into a struct. Additionally, it’s necessary to parse any “$ref” fields, which always contain a JSON file path with a corresponding field name, such as “b.json” with the field “leaveOrganizationRoom”. Consequently, it’s essential to unmarshal the corresponding code as well. After parsing “$ref”, our JSON schema appears as described.
{
"leaveOrganizationRoom": {
"description": "User switches between organization or disconnects the application",
"publish": {
"summary": "Leave Organization Room"
}
}
}
How can I achieve this functionality?